bat--批处理---修改文本内容

来源:百度知道 编辑:UC知道 时间:2024/06/23 08:25:53
文本内容如下
-----------------------------------------
<?xml version="1.0" encoding="UTF-8" ?><user>
<item save_pass="1" user="name1" pass="pass1" disabled="0"/>
<item save_pass="1" user="name2" pass="pass2" disabled="0"/>
<item save_pass="1" user="name3" pass="pass3" disabled="0"/>
<item save_pass="1" user="name4" pass="pass4" disabled="0"/>
<item save_pass="1" user="name5" pass="pass5" disabled="0"/>
</user>
------------------------------------------------------------
文本一共有 7行 首尾2行都不管,中间有5行
单独把这5行拿来分析,比如原来这5行排序是1-5
我想通过批处理调整排序到5-1
大侠帮忙写一下批处理代码

@echo off
for /f "skip=1 delims=/>" %%i in ('type a.xlm')do call:cm "%%i"
echo ^<?xml version="1.0" encoding="UTF-8" ?^>^<user^> >ok.xlm
echo ^%e%/^> >>ok.xlm
echo ^%d%/^> >>ok.xlm
echo ^%c%/^> >>ok.xlm
echo ^%b%/^> >>ok.xlm
echo ^%a%/^> >>ok.xlm
echo ^</user^> >>ok.xlm
pause&exit /b
:cm
if not defined a set "a=%~1"&goto eof
if not defined b set "b=%~1"&goto eof
if not defined c set "c=%~1"&goto eof
if not defined d set "d=%~1"&goto eof
if not defined e set "e=%~1"&goto eof
:eof

你将你文件改成a.xlm,生成的文件是ok.xlm。这2个你可以自己设置的!

1.txt为你的文本内容 3.txt为调整后的内容 有问题请再补充

@echo off
type 1.txt|findstr /n "item">>2.txt
for %%i in (6 5 4 3 2) do (for /f "delims=: tokens=2" %%a