求一批处理,按关键字截取txt文本内容,然后生成新的txt
1个回答
展开全部
@echo off
setlocal enabledelayedexpansion
set fn=E:\a\jpm1.txt
set s=-1
set f=
for /f "delims=:" %%i in ('findstr /n "正文" %fn%') do (
set /a e=%%i-1
if !s!==0 set /a f+=1&&echo sed -n '!s!,!e!p' %fn%^>!f!.txt>>cl.bat
if !s! gtr 0 set /a f+=1&&echo sed -n '!s!,!e!p' %fn%^>!f!.txt>>cl.bat
set /a s=%%i
)
set /a s=!e!
set /a f+=1
echo !f! !s! 9999
echo sed -n '!s!,$p' %fn%^>!f!.txt>>cl.bat
cl.bat
setlocal enabledelayedexpansion
set fn=E:\a\jpm1.txt
set s=-1
set f=
for /f "delims=:" %%i in ('findstr /n "正文" %fn%') do (
set /a e=%%i-1
if !s!==0 set /a f+=1&&echo sed -n '!s!,!e!p' %fn%^>!f!.txt>>cl.bat
if !s! gtr 0 set /a f+=1&&echo sed -n '!s!,!e!p' %fn%^>!f!.txt>>cl.bat
set /a s=%%i
)
set /a s=!e!
set /a f+=1
echo !f! !s! 9999
echo sed -n '!s!,$p' %fn%^>!f!.txt>>cl.bat
cl.bat
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询