回复 3# zllk
可用第 3 方工具 gawk ( http://bcn.bathome.net/tool/4.1.0/gawk.exe )来实现。
bat 脚本方式如下:- @echo off
- ::保存为ANSI编码
- cd /d "%~dp0"
- for /f "usebackq delims=" %%a IN (`dir/b *.txt^|findstr /RE /V "\.文档.[0-9][0-9]*\.txt"`) DO @gawk "FNR==1{i=1;F=substr(FILENAME,1,length(FILENAME)-3);Fn=sprintf(\"%%s文档%%02d%%s\",F,i,\".txt\")}/^A$/{$0=\"12345A\";if(NR==1){i=1}else{i++};Fn=sprintf(\"%%s文档%%02d%%s\",F,i,\".txt\")}{print $0>(Fn)}" %%a
复制代码 命令行方式如下:- for /f "usebackq delims=" %a IN (`dir/b *.txt^|findstr /RE /V "\.文档.[0-9][0-9]*\.txt"`) DO @gawk "FNR==1{i=1;F=substr(FILENAME,1,length(FILENAME)-3);Fn=sprintf(\"%s文档%02d%s\",F,i,\".txt\")}/^A$/{$0=\"12345A\";if(NR==1){i=1}else{i++};Fn=sprintf(\"%s文档%02d%s\",F,i,\".txt\")}{print $0>(Fn)}" %a
复制代码
|