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

[文本处理] 批处理如何将文本内容按指定字数分行(如15个字自动换行)?

a.txt
例文:
的打斗场面令人震撼可谓招招见拳拳到肉记者倪自放囘力街区有望月上映保罗飙车神技将再现由基美影业与囯欧罗巴联合出品囯际著名导演吕克贝松身兼三职担纲监制制片编剧的动作电影囘力街区有望在今年月登陆囯内院线作为吕克贝松风靡全球的经典动作电影囘力区的升级版该片还是好莱坞巨星速度与激囘情系列主演保罗沃克最后一部完整遗囘作曰前该片 的打……
处理后效果:
的打斗场面令人震撼可谓招招见拳
拳到肉记者倪自放囘力街区有望月
上映保罗飙车神技将再现由基美影
业与囯欧罗巴联合出品囯际著名导
演吕克贝松身兼三职担纲监制制片
……
你哪位大神能够教教我,在此感激不尽了…

目录下有多个类似a.txt文件,现在需要把txt文件按固定字数进行自动换行,例如15个字进行自动换行。
学习

换行完成生成新文件
学习

TOP

1>1/* :Bat+JScript
@echo off
cscript -nologo -e:jscript "%~0" <a.txt >b.txt
pause & exit /b
*/

WSH.Echo(
        WSH.StdIn.ReadAll().replace(/.{15}/gm,"$&\r\n")
)这个是单独处理一个文件的,请教处理目录下的多个txt文件,怎么修改
学习

TOP

下面这样处理
  1. var fso = new ActiveXObject("Scripting.FileSystemObject");
  2. while (!WSH.StdIn.AtEndOfStream) {
  3.       var f= fso.OpenTextFile(WSH.StdIn.ReadLine());
  4.       var text = f.ReadAll().replace(/.{15}/gm,"$&\r\n")
  5.       f.Close();
  6.       WSH.Echo(text);
  7. }
复制代码

TOP

感谢楼上谢谢
学习

TOP

回复 5# lianglidong

cscript -nologo -e:jscript "%~0" 改为
  1. dir /b *.txt |cscript -nologo -e:jscript "%~0"
复制代码

TOP

回复 4# terse
如果我要指定不同长度怎么分行,例如我和一行要16个字,第二行可能在6个字换行,三个行可能又更多。以此推类

TOP

回复 7# hqinghua


    为啥不一次性说完呢

TOP

本帖最后由 qixiaobin0715 于 2022-11-30 08:45 编辑

回复 7# hqinghua
这么没有规律性,直接在文本上修改不就可以了。
你应当把你的需求好好总结一下,把规律说清楚。

TOP

回复 8# pd1
你好,也就是想把如下1文本改成2文本那样,做个批处理,这样直接可以用,如果手动修改数据量太大了,有很多文件都是这样的
1.文本
5A56043E2530009DBF1084000002C804848000265A51B5AA6AD54A0140E00D82200800B40024420AE36D5B7041B44D2019E12600A180082006008500002C51A3020015263A4F636BA194CD6935764C4A3B2D1E11080015263A4F636BA194CD6935764C4A3B2D1E110800858000120000204408006047000010220400B023150086000030FE685882BE48E006006015005015565115556115006015005015565115556195AB18800080008000804C2984520109008680000EF0B171EF49C0801A0000000000008700000CFF8168AC226D24000000000087800017910B34002820650C5111E86003428C8C24698171447C148800001F000003E71F17207820D3D4183088418A3928A9C59A7BF5077EE0077E20100088800079457703408AF1FF431008C146A0802418300664C1802107C4E1D06840201D0448404028109070381A104703E2200014E0703800E0E50100280E06435555555555958888888888480906406080002000A143E800001200000220194110060000000092244992040000000092040085110C000040000000005E008900001900000000000000000000000000000000000000000000006400898000130100000C0000000001020101440CCEE77207008A0000809101405EE9EFF7FBFD7E000000F4C582CC2300000000009300E70AD80438B7C009FC7E010E00000000E88360904C0E00000000000000000000ACBEE82B0040A150380FF1668031006721DE0C3006E01CC49B01C6009C817833C018000000000000000000000000000000000000000000000000000000000000000000000000008A800080000000000000000000000000000000000000E81B000000000000000000000000000000000000000000000000000000000C00000001000080120000008DF2330C82100400D0340EB42C0C23490A2A3F00100482300C4DE340CB22490C83A8F2330C82100400D0340EB42C0C23490A2A3F00100482300C4DE340CB22490C8328008B0000160000000000000000000000000000000000000000C0408C00003FEFBDF7DE7BEFBD0708080A0C0C0C0C0C0C0C0C5C09A8AAAAAAAAAAAAAAAAAA5A59595959595959595959590904FF058080000420000108400002108000040F8C80002795938F8C808B8987868483830060F6FFFF2FF3EFFFBF0F0FAFB5710E6C4A6908000000000000008D0000800004080C001014181C002028303800404850580060687078008088909800A0A8B0B800C0C8D0D800E0E8F0F800FCFEFF000004080C001014181C002028303800404850580060687078008088909800A0A8B0B800C0C8D0D800E0E8F0F800FCFEFF000004080C001014181C0020283038004048505800606870780080889098008D800014A0A8B0B800C0C8D0D800E0E8F0F800FCFEFF000090000007A40000000000009100000D2DC40055555555555540551F009180001901050005000000000000000000000000FF0000002400000000920000100003009DBF100000000000000000302501FE
2.文本
0D E8 04 3E 83 75 00 9D BF 10

84 00 00 02
C8 00

84 80 00 26
5A 51 B5 AA 6A D5 4A 01 40 E1 0D 82 20 08 00 B4
00 24 42 0A E3 6D 1B F1 E0 AA 75 20 05 A1 26 00
A1 80 08 20 06 00

85 00 00 2C
CB 96 01 07 16 22 30 40 51 57 89 63 9A A1 72 96
68 62 50 3D 28 14 08 0B 16 22 30 40 51 57 89 63
9A A1 72 96 68 62 50 3D 28 14 08 00

85 80 00 12
00 00 20 44 08 00 60 47 00 00 10 22 04 00 B0 23
15 00

86 00 00 30
FE 68 58 02 3C 64 B8 06 00 60 15 00 50 15 56 51
15 55 61 15 00 60 15 00 50 15 56 51 15 55 61 95
AB 18 80 00 80 00 80 00 80 4C 29 84 52 01 09 00

86 80 00 0E
F0 B1 71 EF 49 C0 80 1A 00 00 00 00 00 00

87 00 00 0C
FF 81 68 AC 22 6D 24 00 00 00 00 00

87 80 00 17
0D 08 4A 00 25 80 64 0C 51 71 48 91 03 62 8C 8C
24 69 81 71 44 7C 14

88 00 00 1F
00 00 03 E7 1F 17 00 78 00 03 D4 18 30 88 41 8A
39 28 A9 C5 9A 7B F5 07 7E E0 07 7E 20 10 00

88 80 00 79
44 77 03 40 8A F1 FF 43 30 08 C1 46 A0 80 24 18
30 06 64 C1 80 21 07 C4 E1 D0 68 40 20 1D 04 48
40 40 28 10 90 70 38 1A 10 47 03 E2 20 00 1C 80
50 30 00 E0 E1 01 00 28 0E 06 03 11 11 11 11 11
91 88 88 88 88 88 C8 08 86 C6 E3 81 00 20 00 21
42 88 00 00 00 00 40 00 00 31 04 41 06 00 00 00
00 92 24 49 92 04 00 00 00 00 00 00 00 85 11 0C
00 00 40 00 00 00 00 5E 00

89 00 00 19
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00

89 80 00 13
01 00 00 0C 00 00 00 00 01 02 01 01 44 0C CE E7
62 06 00

8A 00 00 80
51 02 41 5E E9 EF F7 FB FD 7E 01 00 00 E0 C5 8D
8C 7C 20 66 64 E4 03 13 20 23 1F 98 02 19 F9 C0
01 90 C9 F1 0E 80 4C 0E 0F CA 8B E2 E2 41 0E 20
88 8A 07 39 00 00 10 00 00 5C BC BD 2B 00 40 A1
50 F8 17 32 F2 81 31 00 FF 41 46 3E 30 06 E0 1F
C8 C8 07 C6 00 FC 00 19 F9 C0 18 80 7F 23 23 1F
18 03 F0 5F 64 E4 03 63 00 FE 89 8C 7C 60 0C C0
FF 90 91 0F 8C 01 00 01 BF 1F 00 00 00 00 00 00

8A 80 00 80
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 CA EB 26 2B 23 87 20 93 11 31 CA C8 21 C8
E4 66 AE 32 72 08 32 19 11 A3 8C 1C 82 4C 06 E5
B5 C9 CA C8 65 AE 32 32 13 00 00 00 80 96 22 39
00 40 10 41 50 14 82 60 18 C3 70 1C 68 6D 25 AE
7C 9E E3 68 9A A2 58 96 61 48 92 20 B0 D6 D6 2A
B9 20 48 92 61 58 96 A2 68 9A E3 78 1E 69 6D 21
8E 74 1C C3 60 18 82 50 14 41 40 10 00 A0 56 02

8B 00 00 16
02 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 C0 40

8C 00 00 3F
EF BD F7 DE 7B EF BD 07 08 08 0A 0C 0C 0C 0C 0C
0C 0C 0C 5C 09 A8 AA AA AA AA AA AA AA AA AA 5A
59 59 59 59 59 59 59 59 59 59 59 09 04 FF 05 80
80 00 04 20 00 01 08 40 00 02 10 80 00 04 0F

8C 80 00 27
95 93 8F 8C 80 8B 89 87 86 84 83 83 00 60 F6 FF
FF 2F F3 EF FF BF 0F 0F AF B5 71 0E 6C 4A 69 08
00 00 00 00 00 00 00

8D 00 00 80
00 04 08 0C 00 10 14 18 1C 00 20 28 30 38 00 40
48 50 58 00 60 68 70 78 00 80 88 90 98 00 A0 A8
B0 B8 00 C0 C8 D0 D8 00 E0 E8 F0 F8 00 FC FE FF
00 00 04 08 0C 00 10 14 18 1C 00 20 28 30 38 00
40 48 50 58 00 60 68 70 78 00 80 88 90 98 00 A0
A8 B0 B8 00 C0 C8 D0 D8 00 E0 E8 F0 F8 00 FC FE
FF 00 00 04 08 0C 00 10 14 18 1C 00 20 28 30 38
00 40 48 50 58 00 60 68 70 78 00 80 88 90 98 00

8D 80 00 14
A0 A8 B0 B8 00 C0 C8 D0 D8 00 E0 E8 F0 F8 00 FC
FE FF 00 00

90 00 00 07
90 00 00 00 00 00 00

91 00 00 0D
2D D3 00 41 10 04 41 10 04 41 10 1E 00

91 80 00 19
01 05 00 05 00 00 00 00 00 00 00 00 00 00 00 00
FF 00 00 00 24 00 00 00 00

92 00 00 10
00 03 00 9D BF 10 00 00 00 00 00 00 00 00 75 83

01 FE

TOP

回复 10# hqinghua


    根据啥规律改成2.txt的

QQ 20147578

TOP

回复 11# czjt1234
你好,这个是我自已手动改的

TOP

把你的标准格式放在geshi.txt里,你手动做一个就行。然后bat文件和其他txt文件放在同一个目录下运行。
https://easychuan.cn/r/2eex2?t=ff
按这个附件试试看,记住要处理的文本里字符串个数要和标准格式一致吧,不一致的话没考虑
  1. <# :
  2. @echo off
  3. powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0' |Out-String|Invoke-Expression"
  4. pause
  5. #>
  6. dir *.txt|?{$_.Name -ne "geshi.txt"}|%{
  7. $name=$_.basename
  8. $a=gc $_
  9. $aa=@()
  10. for($i=0;$i -le $a.Length;$i=$i+2){$aa+=$a[$i]+$a[$i+1]}
  11. $m=0
  12. gc .\geshi.txt|%{
  13. if($_.length -eq 0)
  14. {
  15. $n=0;
  16. ""|out-file ($name+"_result.txt") -append
  17. }
  18. else
  19. {
  20. $n=($_.length+1)/3
  21. [system.String]::Join(' ', $aa[$m..($m+$n)]) |out-file ($name+"_result.txt") -append
  22. $m+=$n
  23. }
  24. }
  25. }
复制代码

TOP

回复 13# pd1
好的,我试试
谢谢!

TOP

回复 13# pd1
大师我这边试了一下,第二行的数值都会往前面一行后面写同样的参数,如下
5A 56 04 3E 25 30 00 9D BF 10 84

84 00 00 02 C8
C8 04 84

84 80 00 26 5A
5A 51 B5 AA 6A D5 4A 01 40 E0 0D 82 20 08 00 B4 00
00 24 42 0A E3 6D 5B 70 41 B4 4D 20 19 E1 26 00 A1
A1 80 08 20 06 00 85

85 00 00 2C 51
51 A3 02 00 15 26 3A 4F 63 6B A1 94 CD 69 35 76 4C
4C 4A 3B 2D 1E 11 08 00 15 26 3A 4F 63 6B A1 94 CD
CD 69 35 76 4C 4A 3B 2D 1E 11 08 00 85

  看下是否还能修改一下
谢谢了!

TOP

返回列表