--我在这里学了一下,可以用下面的命令达到效果:
copy build*.pub bb.txt
for /f "tokens=2 delims=>" %%a in ('findstr /i /c:"可售" bb.txt') do echo=%%a >>b1.txt
for /f "tokens=1 delims=</td" %%b in (b1.txt) do echo=%%b >>b2.txt
for /f "tokens=1-2 delims=套 " %%c in (b2.txt) do echo=%%c;%%d>>b3.txt
for /f "tokens=1-3 delims=:" %%e in (b3.txt) do echo=%%e;%%f;%%g>>b4.txt
echo=总售;=sum(b1:b1579);可售;=sum(d1:d1579)>>b4.txt
del b1.txt =总售:199套 可售:199套</td
del b2.txt=总售:199套 可售:199套
del b3.txt=总售:199;可售:199
b4.txt=总售;199;可售;199
我不想用第三方命令,用下面的方法,能删除变量的前后部分,但对中间的无效,它也不能替换为;号
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in (1.txt) do (
set str=%%i
set str=!str:~33,-5!
echo=!str!>>b3.txt
)
经过测试,如果不用 set str=!str:~33,-5!
改用如下代码,可以得到
==;总售;199;可售;199;
==;总售;347;可售;263;
==;总售;580;可售;570;
==;总售;612;可售;589;
这效果,也够用了。
代码
@echo off
del a2.txt
setlocal enabledelayedexpansion
>a2.txt type nul
for /f "tokens=*" %%i in (1.txt) do (
set str=%%i
set "str=!str: =!"
set str=!str::=;!
set str=!str:套=;!
set str=!str:td id=!
set str=!str:"saleinfo" align=!
set str=!str:"center"=!
set str=!str:/td=!
set "str=!str:<>=!"
set "str=!str:<=!"
set "str=!str:>=;!"
>>a2.txt echo,!str!
)
call exit
set str=!str:~33,-5!
@echo off
setlocal enabledelayedexpansion
>a0.txt type nul
for /f "tokens=*" %%i in ('findstr /i /c:"可售" bb.txt') do (
set str=%%i
set "str=!str:*总售:=总售;!"
set "str=!str:套</td>=!"
set "str=!str:套 =!"
set str=!str::=;!
>>a0.txt echo,!str!
)
`call exit
@echo off
>a1.txt type nul
echo=总售;=sum(b2:b3000);可售;=sum(d2:d3000)>>a1.txt
for /f "tokens=3,4,6,7 delims=<>&;:套" %%a in ('findstr /i /c:"可售" bb.txt') do (echo,%%a;%%b;%%c;%%d>>a1.txt)
`call exit
@echo off
setlocal enabledelayedexpansion
>a2.txt type nul
echo=ab;总售;=sum(c2:c3000);可售;=sum(e2:e3000)>>a2.txt
for /f "tokens=*" %%i in ('findstr /i /c:"可售" bb.txt') do (
set str=%%i
set "str=!str: =!"
set str=!str::=;!
set str=!str:套=;!
set str=!str:td id=!
set str=!str:"saleinfo" align=!
set str=!str:"center"=!
set str=!str:/td=!
set "str=!str:<>=!"
set "str=!str:<=!"
set "str=!str:>=;!"
>>a2.txt echo,!str!
)
`call exit
@echo off
setlocal enabledelayedexpansion
>a3.txt type nul
echo=总售;=sum(b2:b3000);可售;=sum(d2:d3000)>>a3.txt
for /f "tokens=*" %%i in ('findstr /i /c:"可售" bb.txt') do (
set str=%%i
set str=!str:~33,-5!
set "str=!str: =!"
set str=!str::=;!
set str=!str:套=!
>>a3.txt echo,!str!
)
`call exit
@echo off
>a4.txt type nul
for /f "tokens=2 delims=>" %%a in ('findstr /i /c:"可售" bb.txt') do echo=%%a >>b1.txt
for /f "tokens=1 delims=</td" %%b in (b1.txt) do echo=%%b >>b2.txt
for /f "tokens=1-2 delims=套 " %%c in (b2.txt) do echo=%%c;%%d>>b3.txt
echo=总售;=sum(b2:b3000);可售;=sum(d2:d3000)>>a4.txt
for /f "tokens=1-3 delims=:" %%e in (b3.txt) do echo=%%e;%%f;%%g>>a4.txt