use*_*547 5 windows dos batch-file findstr
我有一系列日志文件。
我使用 findstr 解析这些日志文件以确定文本字符串的第一个实例,然后返回文件名和找到匹配项的行木材作为变量。
然后我使用 findstr 来解析在另一个文本字符串中找到匹配项的文件。我将匹配的行号作为变量返回。
我现在有了文件,开始和结束行号。
我需要返回行号之间的文本块。
所有输出都被重定向到一个由变量 casenotes 表示的文本文件
这是我的代码:
:test
echo: >> %casenotes%
echo: test >> %casenotes%
for /f "tokens=1,2* delims=:" %%a in ('findstr /N /C:"Optimize ThreadPools" *_MAGT_*.txt') do set startline=%%b & set filefoundin=%%a & goto part2
:part2
for /f "tokens=1,2* delims=:" %%a in ('findstr /N /C:"After optimization" %filefoundin%') do set endline=%%a & goto part3
:part3
echo: >> %casenotes%
echo: filefound in: %filefoundin% >> %casenotes%
echo: startline is: %startline% >> %casenotes%
echo: endline is: %endline% >> %casenotes%
echo: >> %casenotes%
echo: now do something magic to read everything between lines %startline% and %endline% from %filefoundin% and redirect that output to %casenotes%
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏!
试试这个:@echo 关闭
set file_to_read=read.txt
set /a start_line=1
set /a end_line=6
set outfile=outfile
set counter=1
break > %outfile%
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=*" %%A in (%file_to_read%) do (
if !counter! GEQ !start_line! (
echo %%A
echo %%A >> !outfile!
)
set /A counter=!counter!+1
if !counter! GEQ !end_line! (
goto :endLoop
)
)
:endLoop
Run Code Online (Sandbox Code Playgroud)
这不会计算空行。
| 归档时间: |
|
| 查看次数: |
3231 次 |
| 最近记录: |