|
Answer» Hi everyone!
I have a problem with trying to convert a file which has a single line text into fixed length multiple lines.
In Unix you can use the "Fold" command to determine the length but I cant find anything in DOS (or Windows scripting) that would perform the same function.
I WANT to read the file with a single line (of random length) and create a line break at x number of bytes along and then output the results into another file. So if the line in the file was 1000 bytes in length and I wanted a break at 100 bytes, I would end up with a file of 10 lines at 100 bytes in length each.
Thanks in advance, any help would be much appreciated.You didn't mention an OS, and a batch solution would only work on some OSes. This little VBScript should work on any Windows machine.
Code: [Select]Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("[highlight]c:\unfold.txt[/highlight]", ForReading) strLong = f.ReadAll f.Close
Set f = fso.CreateTextFile("[highlight]c:\fold.txt[/highlight]")
i = 1 Do Until i > Len(strLong) f.WriteLine Mid(strLong, i, 100) i = i + 100 Loop f.Close
The script was WRITTEN based on your specs, but can easily be changed for different length records. After saving the script with a vbs extension, run as cscript scriptname.vbs
Note: Change the HIGHLIGHTED file and path names to something appropriate.
8-)
Didn't have this is my SNIPPET closet, actually had to write this *gasp*
Quote Hi everyone!
I have a problem with trying to convert a file which has a single line text into fixed length multiple lines.
In Unix you can use the "Fold" command to determine the length but I cant find anything in DOS (or Windows scripting) that would perform the same function.
I want to read the file with a single line (of random length) and create a line break at x number of bytes along and then output the results into another file. So if the line in the file was 1000 bytes in length and I wanted a break at 100 bytes, I would end up with a file of 10 lines at 100 bytes in length each.
Thanks in advance, any help would be much appreciated.
well, in windows you can use fold too.. http://unxutils.sourceforge.net/
|