Board logo

标题: [文本处理] 批处理如何查找到文本中含有指定字符串时在该行后面加上特定字符串? [打印本页]

作者: welky    时间: 2009-4-7 21:13     标题: 批处理如何查找到文本中含有指定字符串时在该行后面加上特定字符串?

如c:\test.txt文件中有如下内容:

"我爱BAT!"
call c:\test\test.bat
echo copy finished!

想找到以"call"开头的行后面加上字符串" -- -p test.class"
完成后应该如下:
"我爱BAT!"
call c:\test\test.bat -- -p test.class
echo copy finished!

请问该怎么实现?
谢谢
作者: zhouyongjun    时间: 2009-4-7 23:25

  1. @echo off
  2. for /f "delims=" %%i in (test.txt) do (
  3. echo.%%i|findstr/i ^call.*$ >nul 2>nul&&echo %%i-- -p test.class>>_test.txt||echo %%i>>_test.txt
  4. )
复制代码

作者: 随风    时间: 2009-4-8 00:04

  1. @echo off
  2. for /f "delims=" %%a in ('findstr /b "call" a.txt') do set %%a=a
  3. for /f "delims=" %%a in (a.txt) do (
  4.    if not defined %%a (echo %%a) else echo %%a -- -p test.class
  5. )
  6. pause
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2