[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

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

本帖最后由 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
1

评分人数

    • CrLf: 感谢给帖子标题标注[已解决]字样PB + 2
诗意地栖居

  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
复制代码

TOP

本帖最后由 452452 于 2011-10-28 11:51 编辑

代码没有把" 替换为&nettype= 测试结果只有一行
http://www.cdvdbest.com/cgi-bin/forsearch/vip/download.pl?dirno93115852&pagenum0011
诗意地栖居

TOP

  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
复制代码
1

评分人数

    • CrLf: 乐于助人技术 + 1

TOP

  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
复制代码
1

评分人数

    • CrLf: 乐于助人技术 + 1

TOP

4楼、5楼的代码没有生成文本结果,请再测试一下。
诗意地栖居

TOP

回复 6# 452452


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

要生成结果:
  1. echo !str!!num! >>url.txt
复制代码

TOP

回复 7# sxw


    要生成结果,是不是把echo !str!!num!改为echo !str!!num! >>url.txt就行了吗?
诗意地栖居

TOP

回复 8# 452452


    要生成文件你只要把最后那个反括号)改成)>url.txt就可以了

TOP

回复 8# 452452


    是啊

TOP

  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
复制代码

TOP

返回列表