Board logo

标题: [文本处理] [已解决]批处理如何替换字符后在每行最后插入/添加递增的数字序号? [打印本页]

作者: 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

  1. @echo off
  2. for /f "delims=" %%a in (url.txt) do (
  3.    set /a n+=10001
  4.    set str=%%a
  5.    setlocal enabledelayedexpansion
  6.    for %%b in (!n:~-4!) do echo !str:"=%%b!
  7.    endlocal
  8. )>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

  1. @echo off&setlocal enabledelayedexpansion
  2. set n=10000
  3. for /f "delims=" %%i in (text.txt) do (set /a n+=1
  4. set x=%%i
  5. echo !x:~0,-2!^&nettype=!n:~-4!
  6. )
  7. pause
复制代码

作者: sxw    时间: 2011-10-28 12:07

  1. @echo off&setlocal enabledelayedexpansion
  2. set n=1
  3. for /f "delims=" %%i in (a.txt) do (
  4. set num=000!n!
  5. set num=!num:~-4!
  6. set str=%%i
  7. set str=!str:"=&nettype=!
  8. set str=!str: =!
  9. echo !str!!num!
  10. set /a n+=1
  11. )
  12. pause
复制代码

作者: 452452    时间: 2011-10-28 12:26

4楼、5楼的代码没有生成文本结果,请再测试一下。
作者: sxw    时间: 2011-10-28 12:44

回复 6# 452452


    你把你要处理的文本保存为a.txt

要生成结果:
  1. 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

  1. @echo off
  2. (for /f "delims=" %%a in (url.txt) do (
  3.    set /a n+=10001
  4.    set str=%%a
  5.    setlocal enabledelayedexpansion
  6.    for %%b in (!n:~-4!) do echo !str:"=&nettype=%%b!
  7.    endlocal
  8. ))>url2.txt
复制代码





欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2