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

[文本处理] 批处理能否对数字串重排序号?

【示例】:
1
1
1
1
1
1
1
1
1
1
1
……
1
1
1
……
1
1
……

【要求按顺序排列】:
1
2
3
4
5
6
7
8
9
10
11
……
999
1000
1001
……
9999
10000
……

示例中全是1。。。不明白如何变成序列?
***共同提高***

TOP

回复 2# batman


    额,其实是这样的,1是个变量,第一列可以是:

1
3
5
7
3
8
6
9
……
之类的不规则顺序。

如果它们前后有固定的标志,那就简单了,我可以用宏脚本处理的,但去掉了固定标志,用批处理还能不能按顺序排列呢?

比如:
第1章
第3章
第5章
第7章
……
第N章

用下面的宏脚本可以按顺序排序成:

第1章
第2章
第3章
第4章
……
第N章
  1. document.selection.Replace("\n\n\n第","hhhhhhhhhhh第",eeFindNext | eeReplaceAll);
  2. document.selection.Replace("\n","jjjjjjjjj",eeFindNext | eeReplaceAll);
  3. document.selection.Replace("hhhhhhhhhhh","\n",eeFindNext | eeReplaceAll);
  4. document.selection.Replace(".*.章 jjjjjjjjj","",nFlags);
  5. document.selection.Replace("jjjjjjjjj","",eeFindNext | eeReplaceAll);
  6. document.selection.PageDown(false,50000);
  7. document.selection.EndOfLine(false,eeLineView);
  8. document.selection.NewLine(1);
  9. document.selection.PageUp(false,50000);
  10. document.selection.Text="aaaaaa1bbbbbb";
  11. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  12. document.selection.LineDown(false,1);
  13. document.selection.Text="aaaaaa2bbbbbb";
  14. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  15. document.selection.LineDown(false,1);
  16. document.selection.Text="aaaaaa3bbbbbb";
  17. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  18. document.selection.LineDown(false,1);
  19. document.selection.Text="aaaaaa4bbbbbb";
  20. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  21. document.selection.LineDown(false,1);
  22. document.selection.Text="aaaaaa5bbbbbb";
  23. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  24. document.selection.LineDown(false,1);
  25. document.selection.Text="aaaaaa6bbbbbb";
  26. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  27. document.selection.LineDown(false,1);
  28. document.selection.Text="aaaaaa7bbbbbb";
  29. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  30. document.selection.LineDown(false,1);
  31. document.selection.Text="aaaaaa8bbbbbb";
  32. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  33. document.selection.LineDown(false,1);
  34. document.selection.Text="aaaaaa9bbbbbb";
  35. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  36. document.selection.LineDown(false,1);
  37. document.selection.Text="aaaaaa10bbbbbb";
  38. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  39. document.selection.LineDown(false,1);
  40. document.selection.Text="aaaaaa11bbbbbb";
  41. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  42. document.selection.LineDown(false,1);
  43. document.selection.Text="aaaaaa12bbbbbb";
  44. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  45. document.selection.LineDown(false,1);
  46. document.selection.Text="aaaaaa13bbbbbb";
  47. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  48. document.selection.LineDown(false,1);
  49. document.selection.Text="aaaaaa14bbbbbb";
  50. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  51. document.selection.LineDown(false,1);
  52. document.selection.Text="aaaaaa15bbbbbb";
  53. ……
  54. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  55. document.selection.LineDown(false,1);
  56. document.selection.Text="aaaaaa3997bbbbbb";
  57. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  58. document.selection.LineDown(false,1);
  59. document.selection.Text="aaaaaa3998bbbbbb";
  60. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  61. document.selection.LineDown(false,1);
  62. document.selection.Text="aaaaaa3999bbbbbb";
  63. document.selection.StartOfLine(false,eeLineView | eeLineHomeText);
  64. document.selection.LineDown(false,1);
  65. document.selection.Text="aaaaaa4000bbbbbb";
  66. ……
复制代码

TOP

  1. @echo off&setlocal enabledelayedexpansion
  2. for /f %%a in (a.txt) do (
  3.   set "str=..........%%a"
  4.   set "str=!str:~-10!"
  5.   set "!str!=a"
  6. )
  7. (for /f "delims=.=" %%a in ('set .') do echo %%a)>$
  8. move $ a.txt
  9. start a.txt
  10.   
  11.   
复制代码
***共同提高***

TOP

回复 4# batman


    额,俺说的按顺序是将原来的每行的1,1,1……变成1,2,3……这种顺序,是要替换的。

再如下面10列:
1
3
5
6
7
8
9
2
6
8
……

要先替换不正确的序号,并按顺序排列:

1
2
3
4
5
6
7
8
9
10

TOP

请楼主一次性将问题描述清楚

别人帮人不能靠猜的。。。
***共同提高***

TOP

回复 6# batman


    。。俺认为示例里面已经很清楚了啊。。。 额。。

TOP

我也完全没看懂

TOP

没看懂的路过

TOP

回复 8# CrLf


    好吧,退而求其次,我尽量解释清楚。网络小说看过吧,拿《诛仙》为例,它的章节目录是这样的:


第1章 青云
第2章 迷局
第3章 宏愿
第4章 惊变
第5章 入门
第6章 拜师
第7章 初始
第8章 传艺
第9章 佛与道
第10章 幽谷


但有人为了防盗版,故意把正确目录变成如下:

第1章 青云
第1章 迷局
第1章 宏愿
第1章 惊变
第1章 入门
第1章 拜师
第1章 初始
第1章 传艺
第1章 佛与道
第1章 幽谷

看懂了吗?所有的序号都变成了1。

而我所提出的【按顺序排列】就是将下面【错误的序号】替换为上面【正确的序号】。明白?很难理解么。。。

TOP

所以你只要For /f在加上一个记录行号的变量,处理每行,把1换成现在的行号不久行了么?

要么,直接把要操作的文件传上来

TOP

返回列表