本帖最后由 tmplinshi 于 2012-11-17 17:32 编辑
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :: 工具下载地址
- :: sed 4.0.7 win换行
- :: http://bathome.net/thread-15605-1-4.html
- ::
- :: GNU Awk 3.1.0
- :: http://sourceforge.net/projects/unxutils/files/
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- @echo off
-
- :: --------------------- 设置 ---------------------
- set "folder=e:\我的文档\桌面"
- set "filename=a.xml"
- set "str=xxxx"
- :: --------------------- /设置 ---------------------
-
- :: 创建文件列表
- dir /s /b "%folder%\%filename%" >.tmp
-
- :: 统计文件个数
- for /f %%a in (' find /c /v "" ^< .tmp ') do (
- set /a total = %%a, count = 0
- )
-
- :: 替换
- for /f "delims=" %%a in (.tmp) do (
- call :replace "%%a"
- )
-
- :: 退出
- set /p =处理完毕!按回车键退出. . . <nul
- pause >nul
- exit /b
-
-
- :replace
- set /a count += 1
- title %count% / %total%
- echo %1
-
- gawk "{gsub(/%str%/,\"\n^&\")};{print}" FS="%str%" %1 | gawk "{sub(/%str%/,++n-1 \"^&\");print}" | sed -r ":a;N;$!ba;s/\n([0-9]+)%str%/\1/g" >.tmp
-
- move .tmp %1
- goto :eof
复制代码 下载“gawk.exe sed.exe test.bat.zip”:
http://files.getwebb.org/view-cre63ai1.html |