建议借助sed这类流编辑命令行(如果没有可百度下载,我的版本是:sed.exe 4.1.4),效率、兼容性都很高:
@echo off
sed "s/^AAAA.*/BBBB/;/^CCCC/s/\(,\).*/\1DDDD/" 1.txt
pause
当然纯批处理也不是没办法,只不过各方面稍逊不少:
@echo off
SetLocal EnableDelayedExpansion
for /f "delims=" %%i in ('type 1.txt') do (
set "x=%%i"
if "!x:~,4!"=="AAAA" (set "x=BBBB") else (
if "!x:~,4!"=="CCCC" for /f "delims=," %%i in ("%%i") do set "x=%%i,DDDD"
)
echo;!x!
)
pause