ANSI编码;空行也算在行号内:- @echo off&setlocal enabledelayedexpansion
- set a=11
- for /f "tokens=1-3* delims=:" %%a in ('findstr /n .* myfile.txt') do if %%a==!a! (
- if "!b!"=="1" (set/a b=11,c+=%%c&echo !c!) else set/a b=1,c=%%c
- set/a a+=b
- )
- pause
复制代码 如果文本行数远多于84,而只提取前84行,则:- @echo off&setlocal enabledelayedexpansion
- set a=11
- for /f "tokens=1-3* delims=:" %%a in ('findstr /n .* myfile.txt') do (
- if %%a==!a! (
- if "!b!"=="1" (set/a b=11,c+=%%c&echo !c!) else set/a b=1,c=%%c
- set/a a+=b
- )
- if %%a==84 goto:end
- )
- :end
- pause
复制代码
如果要忽略空行以及;开头的行,则- @echo off&setlocal enabledelayedexpansion
- set a=11
- for /f "tokens=2 delims=:" %%a in (myfile.txt) do (
- set/a n+=1
- if !n!==!a! (
- if "!b!"=="1" (set/a b=11,c+=%%a&echo !c!) else set/a b=1,c=%%a
- set/a a+=b
- )
- if !n!==84 goto:end
- )
- :end
- pause
复制代码
[ 本帖最后由 hanyeguxing 于 2010-12-23 21:24 编辑 ] |