标题: [文本处理] [已解决]批处理如何替换字符后在每行最后插入/添加递增的数字序号? [打印本页]
作者: 452452 时间: 2011-10-28 10:34 标题: [已解决]批处理如何替换字符后在每行最后插入/添加递增的数字序号?
本帖最后由 pcl_test 于 2017-6-5 09:42 编辑
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno02124024&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno02134323&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno03112283&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno96119125&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno96107695&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno95194134&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno95112286&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno97100300&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno92113938&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno93111252&pagenum
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno93115852&pagenum
把" 替换为&nettype=,然后在每行最后追加序列数字0001 0002 0003 0004......
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno02124024&pagenum&nettype=0001
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno02134323&pagenum&nettype=0002
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno03112283&pagenum&nettype=0003
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno96119125&pagenum&nettype=0004
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno96107695&pagenum&nettype=0005
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno95194134&pagenum&nettype=0006
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno95112286&pagenum&nettype=0007
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno97100300&pagenum&nettype=0008
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno92113938&pagenum&nettype=0009
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno93111252&pagenum&nettype=0010
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno93115852&pagenum&nettype=0011
作者: CrLf 时间: 2011-10-28 11:29
- @echo off
- for /f "delims=" %%a in (url.txt) do (
- set /a n+=10001
- set str=%%a
- setlocal enabledelayedexpansion
- for %%b in (!n:~-4!) do echo !str:"=%%b!
- endlocal
- )>url2.txt
复制代码
作者: 452452 时间: 2011-10-28 11:50
本帖最后由 452452 于 2011-10-28 11:51 编辑
代码没有把" 替换为&nettype= 测试结果只有一行
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno93115852&pagenum0011
作者: 601997526 时间: 2011-10-28 12:05
- @echo off&setlocal enabledelayedexpansion
- set n=10000
- for /f "delims=" %%i in (text.txt) do (set /a n+=1
- set x=%%i
- echo !x:~0,-2!^&nettype=!n:~-4!
- )
- pause
复制代码
作者: sxw 时间: 2011-10-28 12:07
- @echo off&setlocal enabledelayedexpansion
- set n=1
- for /f "delims=" %%i in (a.txt) do (
- set num=000!n!
- set num=!num:~-4!
- set str=%%i
- set str=!str:"=&nettype=!
- set str=!str: =!
- echo !str!!num!
- set /a n+=1
- )
- pause
复制代码
作者: 452452 时间: 2011-10-28 12:26
4楼、5楼的代码没有生成文本结果,请再测试一下。
作者: sxw 时间: 2011-10-28 12:44
回复 6# 452452
你把你要处理的文本保存为a.txt
要生成结果:- echo !str!!num! >>url.txt
复制代码
作者: 452452 时间: 2011-10-28 13:02
回复 7# sxw
要生成结果,是不是把echo !str!!num!改为echo !str!!num! >>url.txt就行了吗?
作者: 601997526 时间: 2011-10-28 13:08
回复 8# 452452
要生成文件你只要把最后那个反括号)改成)>url.txt就可以了
作者: sxw 时间: 2011-10-28 13:09
回复 8# 452452
是啊
作者: CrLf 时间: 2011-10-28 13:11
- @echo off
- (for /f "delims=" %%a in (url.txt) do (
- set /a n+=10001
- set str=%%a
- setlocal enabledelayedexpansion
- for %%b in (!n:~-4!) do echo !str:"=&nettype=%%b!
- endlocal
- ))>url2.txt
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |