本帖最后由 CrLf 于 2012-9-25 01:09 编辑
方案一,获取 skip 行数:- @echo off
- for /f "delims=:" %%a in ('findstr /nc:"Enabling public" 测试.txt') do set /a linenum=%%a-6
- for /f "skip=%linenum% tokens=1* delims=: " %%a in (测试.txt) do echo %%b&pause&exit
复制代码 方案二,用变量保存五行:- @echo off&setlocal enabledelayedexpansion
- for /f "tokens=1* delims=: " %%a in (a.txt) do (
- set /a n+=1,n%%=5
- set str=%%b
- if "!str:Enabling public=!" neq "!str!" (
- for %%b in (!n!) do echo !ar[%%b]!&pause&exit
- )
- set "ar[!n!]=%%b"
- )
复制代码 方案三,逆序文本:- @echo off&setlocal enabledelayedexpansion
- set begin=0
- for /f "tokens=1* delims=: " %%a in ('sort /+999 测试.txt') do (
- set str=%%b
- if "!str:Enabling public=!" neq "!str!" set begin=1
- if !n!==5 echo !str!
- if !begin!==1 set /a n+=1
- )
- pause
复制代码 还有其他方案,但我想这三个够用了... |