怎样用批处理批量删除多个文本中含某字的行

当前文件夹中有若干.txt文本文档,怎样用批处理批量删除这些文本中包含某些字符的行,比如“www”、“阅读正文”等,请高手大师们给提供一个批处理文件。
另外,批量删除文本中的空行或指定字符应该怎样写?请一并提供,先谢过了!
您好!您给的这个批处理是单文件的替换,有没有方法批量替换多个文本呢?

第1个回答  2008-12-25
::用指定字符替换指定内容.cmd
@echo off
setlocal enabledelayedexpansion
set file=
set /p file= 请输入要操作的文件名称(包括扩展名):
set "file=%file:"=%"
for %%i in ("%file%") do set file=%%~fi
echo.
set replaced=
set /p replaced= 请输入即将被替换的内容:
echo.
set all=
set /p all= 请输入替换字符串:
for /f "delims=" %%i in ('type "%file%"') do (
set str=%%i
set "str=!str:%replaced%=%all%!"
echo !str!>>"%file%"_tmp.txt
)
copy "%file%" "%file%"_bak.txt >nul 2>nul
move "%file%"_tmp.txt "%file%"
start "" "%file%"

@echo off
:: 删除重复的行,但不能保留空行
:: 对不符合变量命名规则、变量个数超过限制的文本都无法正确处理
:: code by youxi01 modified by jm 2006-10-31
(echo 清除重复行后的文件内容:& echo.)>str_.txt
for /f "delims=" %%i in (test.txt) do (
if not defined %%i set %%i=A & echo %%i>>str_.txt)
start str_.txt
第2个回答  2009-01-02
相似回答