[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 pcl_test 于 2016-11-21 18:22 编辑
  1. #*http://www.bathome.net/s/tool/index.html?down&key=gawk
  2. #*提取多个文本指定字符串所在行之后的10行内容
  3. #*&cls&dir /a-d/b *.txt|gawk -f "%~f0"|find /v ""&pause&exit
  4. BEGIN{
  5.     while(getline file>0){
  6.         t=0;
  7.         while(getline<file>0){
  8.             if(t>0&&t<=11)print;
  9.             if(index($0, "指定字符串"))t=1;
  10.             if(t)t++;if(t>11)break;
  11.         }
  12.     }
  13. }
复制代码
2

评分人数

TOP

#*&cls&dir /a-d/b *.txt|gawk -f "%~f0">"result.log"&pause&exit
http://www.bathome.net/redirect. ... 6603&ptid=22680官网

TOP

本帖最后由 pcl_test 于 2016-11-21 00:14 编辑

回复 6# w609053988
  要你看的是两个官网教程
http://www.gnu.org/software/gawk/manual/gawk.html
http://www.gnu.org/software/sed/manual/sed.html

TOP

本帖最后由 pcl_test 于 2016-12-1 13:36 编辑

回复 9# w609053988

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

评分人数

TOP

#*http://www.bathome.net/s/tool/index.html?down&key=gawk
#*提取多个文本指定字符串所在行之后的10行内容
#*&cls&dir /a-d/b *.txt|gawk -f "%~f0">"result.log"&pause&exit
BEGIN{
    while(getline file>0){
        t=0;print file;
        while(getline<file>0){
            if(t>0&&t<=11)print;
            if(index($0, "指定字符串"))t=1;
            if(t)t++;if(t>11)break;
        }
        close(file);
    }
}
1

评分人数

TOP

返回列表