DOS script to break long line

July 21, 2010 at 11:58:45
Specs: Windows
I have a text file a.txt with long line:

123456789abcdefg12345
....

I want to break the long line to a specific number of characters, and saved it to b.txt, such as 5 character each line:

12345
6789a
bcdef
g1234
5....

The command line should looks like:

cmd1 a.txt b.txt 5

How to write the dos script? Thanks.


See More: DOS script to break long line

Report •

#1
July 21, 2010 at 12:26:44
need to know how long the line is. (there are limits to batch).
(see:
http://www.computing.net/answers/pr...

Report •

#2
July 21, 2010 at 12:40:43
the line maybe as long as thousands. we need a split the long line to 100 character each line. Thanks.

Report •

#3
July 21, 2010 at 14:22:00
well, if in doubt, don't rely on batch. vbscript is prob'ly faster anyway:

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f, Msg
Set fso = CreateObject("Scripting.FileSystemObject")
Set g = fso.OpenTextFile("outfile.txt", ForWriting, True)
Set f = fso.OpenTextFile("infile.txt", ForReading)
do while not f.atendofstream
hundred = f.Read(100)
g.writeline(hundred)
loop
f.close
g.close


Report •

Related Solutions

#4
July 21, 2010 at 17:31:44
download coreutils for windows, then use the split command

c:\test> split -b 5 file

that's all you need

GNU win32 packages | Gawk


Report •

Ask Question