Board logo

标题: [求助]求可以替换文本指定内容的批处理 [打印本页]

作者: yxzpt     时间: 2008-7-26 09:32    标题: [求助]求可以替换文本指定内容的批处理
有a.txt和b.txt 2个文本

a.txt文本内容是每行一串数字,例:
170422
271458
270547
173707
195009
……

b.txt文本内容如下:
msgId=170422&satisficationStar=3&serviceQuality=50&professionLevel=50&responseLevel=50&servicePrice=50&preVisitTime=1&revist=1&evaluation=%E5%8F%91%E5%B8%83

在此求个批处理,每运行一次,将a.txt中的数字串逐行依次替换b.txt的红色部分,a.txt数列不用循环替换。谢谢!

Last edited by yxzpt on 2008-7-26 at 09:36 AM ]

作者: HAT     时间: 2008-7-26 10:18
@echo off
set "str1=msgId="
set "str3=^&satisficationStar=3^&serviceQuality=50^&professionLevel=50^&responseLevel=50^&servicePrice=50^&preVisitTime=1^&revist=1^&evaluation=%%E5%%8F%%91%%E5%%B8%%83"
if not exist c.txt (
>"c.txt" echo 1
)
set /p mark=<c.txt
set cur=1
setlocal enabledelayedexpansion
for /f "usebackq delims=:" %%a in ("a.txt") do (
set str2=%%a
if "%str%" equ "" (
>"c.txt" echo 1
)
if !cur! equ !mark! (
goto :merge
) else (
set /a cur+=1
)
)
endlocal
goto :eof
:merge
>"d.txt" echo %str1%%str2%%str3%
set /a mark+=1
>"c.txt" echo %mark%
move /y d.txt b.txt

作者: yxzpt     时间: 2008-7-26 10:33
谢谢楼上的,测试可以。但由于我的疏忽,没有说清楚,就是我在上面提到的b.txt

“msgId=170422&satisficationStar=3&serviceQuality=50&professionLevel=50&responseLevel=50&servicePrice=50&preVisitTime=1&revist=1&evaluation=%E5%8F%91%E5%B8%83”

只是b.txt内容其中的一部分,请问怎么修改才可以正常使用?

Last edited by yxzpt on 2008-7-26 at 10:41 AM ]

作者: HAT     时间: 2008-7-26 10:39
下次记得在顶楼把问题描述清楚^_^
b.txt的完整内容能贴出来看看吗?

作者: yxzpt     时间: 2008-7-26 10:46
POST /AddEvaluation HTTP/1.1
Accept: text/javascript, text/html, application/xml, text/xml, */*
Accept-Language: zh-cn
x-prototype-version: 1.6.0
Referer: http://yhnrne.vicp.net/detail/212809.html?tag=hometop&cat=101
x-requested-with: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
Host: yhnrne.vicp.net
Content-Length: 270
Connection: Keep-Alive
Cache-Control: no-cache
Cache: infotree_DJGH370=749D03; JSESSIONID=FD2CF8E2A05B50D0CC8EE75D028A8204.AppSer2BTomcat

msgId=170422&satisficationStar=3&serviceQuality=50&professionLevel=50&responseLevel=50&servicePrice=50&preVisitTime=1&revist=1&evaluation=%E5%8F%91%E5%B8%83

作者: HAT     时间: 2008-7-26 11:00
@echo off
set "str1=msgId="
set "str3=^&satisficationStar=3^&serviceQuality=50^&professionLevel=50^&responseLevel=50^&servicePrice=50^&preVisitTime=1^&revist=1^&evaluation=%%E5%%8F%%91%%E5%%B8%%83"
if not exist c.txt (
>"c.txt" echo 1
)
set /p mark=<c.txt
set cur=1
setlocal enabledelayedexpansion
for /f "usebackq delims=:" %%a in ("a.txt") do (
set str2=%%a
if "%str%" equ "" (
>"c.txt" echo 1
)
if !cur! equ !mark! (
goto :merge
) else (
set /a cur+=1
)
)
endlocal
goto :eof
:merge
type nul>"d.txt"
for /f "tokens=1* delims=" %%a in ('findstr /v /i "msgId" "b.txt"') do (
>>"d.txt" echo %%a
)
>>"d.txt" echo.
>>"d.txt" echo %str1%%str2%%str3%
set /a mark+=1
>"c.txt" echo %mark%
move /y d.txt b.txt


Last edited by HAT on 2008-7-26 at 11:02 AM ]

作者: yxzpt     时间: 2008-7-26 11:21
谢谢你的帮助