我的答案:
要求一- @echo off
- setlocal enabledelayedexpansion
- set n=0
- set count=0
- goto :loop
- :up
- set /a count=!n!-2
- for /f "skip=%count% tokens=*" %%j in (a.txt) do (
- echo %%j>>b.txt
- goto :eof
- )
- :loop
- for /f "tokens=*" %%i in (a.txt) do (
- set /a n+=1
- set temp=%%i
- if "!temp:~0,4!"=="abcd" (
- echo %%i>>b.txt
- call :up
- )
- )
- start b.txt
复制代码 要求二- @echo off
- setlocal enabledelayedexpansion
- set n=0
- set count=0
- goto :loop
- :up
- set /a count=!n!-2
- for /f "skip=%count% tokens=*" %%j in (a.txt) do (
- echo %%j>>b.txt
- goto :eof
- )
- :low
- set /a count=!n!
- for /f "skip=%count% tokens=*" %%j in (a.txt) do (
- echo %%j>>b.txt
- goto :eof
- )
- :loop
- for /f "tokens=*" %%i in (a.txt) do (
- set /a n+=1
- set temp=%%i
- if "!temp:~0,4!"=="abcd" (
- echo %%i>>b.txt
- call :up
- call :low
- )
- )
- start b.txt
复制代码 如果原文件以abcd开头行出现的位置<2的话就要加判断语句,否则会报错.
不过按照楼主的a.txt文件,我测试是通过的.
[ 本帖最后由 springcm 于 2008-6-2 07:59 编辑 ] |