本帖最后由 ivor 于 2012-1-16 16:56 编辑
- @echo off & setlocal enabledelayedexpansion
- for /f "delims=" %%i in (a.txt) do (
- set count=0
- for /f "skip=1 delims=" %%j in (a.txt) do (
- if %%i EQU %%j (
- set /a count+=1
-
- )
-
- )
- if NOT !count! GEQ 2 echo %%i>>b.txt
- )
复制代码 下面的代码大幅度优化比较的速度,经测试1000行重复字符串,比上个代码快了30倍- @echo off & setlocal enabledelayedexpansion
-
- set Count=0
- for /f "delims=" %%i in (a.txt) do (
-
- call :cmp
- if !Count! EQU 1 echo %%i >>b.txt
- set Count=0
- )
-
- echo.已经成功执行完了 & pause>nul
- goto :EOF
-
- :cmp
-
- for /f "skip=1 delims=" %%j in (a.txt) do (
-
- if %%i EQU %%j (
- set /a Count+=1
- if !Count! EQU 2 goto :EOF
- )
-
- )
-
-
复制代码
|