要求一:显示a.txt中以 abcd 开头的行和它的上一行。- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('type a.txt') do (
- set /a n+=1,m=n-1
- set _!n!=%%a
- set str=%%a
- if "!str:~,4!"=="abcd" call echo %%_!m!%%&call echo %%_!n!%%
- )
- pause
复制代码 要求二:显示a.txt中以 abcd 开头的行和它的上一行及下一行。- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('type a.txt') do (
- set /a a+=1
- set _!a!=%%a
- )
- for /f "delims=" %%a in ('type a.txt') do (
- set /a n+=1,o=n+1,m=n-1
- set _!n!=%%a
- set str=%%a
- if "!str:~,4!"=="abcd" call echo %%_!m!%%&call echo %%_!n!%%&call echo %%_!o!%%
- )
- pause
复制代码
|