本帖最后由 pcl_test 于 2016-12-1 13:36 编辑
回复 9# w609053988
好吧,转为纯批- @echo off
- for /f "delims=" %%a in ('dir /a-d/b *.txt') do call :loop "%%a"
- pause&exit
- :loop
- setlocal enabledelayedexpansion
- for /f "delims=" %%b in ('type "%~1"') do (
- set "str=%%b"
- if defined t if !t! leq 11 echo;%%b
- if "!str:指定字符串=!" neq "%%b" set t=1;
- if defined t set /a t+=1
- if !t! gtr 11 goto :eof
- )
复制代码
- powershell -c "dir *.txt|%%{if([IO.File]::ReadAllText($_, [Text.Encoding]::Default) -match '(?<=.*?指定字符串.*?\n)(.+?(\n|$)){1,10}'){$matches[0]}}"
- pause
复制代码
- powershell -c "dir *.txt|%%{$t=0;gc $_|%%{if(($t -gt 0) -and ($t -le 11)){$_};if($_.contains('指定字符串')){$t=1};if($t){$t++}}}"
- pause
复制代码
|