Sort Alphabetically Batch File needed - remove space etc....
Moderator: DosItHelp
Sort Alphabetically Batch File needed - remove space etc....
Hi Guys....
I posted about a similar problem last year.This is a lot different.
What I want to do is modify a text file like this:
tester001.tab tester002.tab tester003.tab tester004.tab tester005.tab tester006.tab tester007.tab tester008.tab tester009.tab tester010.tab tester011.tab tester012.tab tester013.tab tester014.tab
and have it look like this:
tester001.tab
tester002.tab
tester003.tab
tester004.tab
etc.........
Even with word wrap on I cannot do what I want.
Please help with a batch file if possible.Thanks a bunch!
PS: The file above is just a shortened version.The real ones have over one thousand tester00x.tab files.
Val
I posted about a similar problem last year.This is a lot different.
What I want to do is modify a text file like this:
tester001.tab tester002.tab tester003.tab tester004.tab tester005.tab tester006.tab tester007.tab tester008.tab tester009.tab tester010.tab tester011.tab tester012.tab tester013.tab tester014.tab
and have it look like this:
tester001.tab
tester002.tab
tester003.tab
tester004.tab
etc.........
Even with word wrap on I cannot do what I want.
Please help with a batch file if possible.Thanks a bunch!
PS: The file above is just a shortened version.The real ones have over one thousand tester00x.tab files.
Val
Re: Sort Alphabetically Batch File needed - remove space etc
val5662 wrote:The real ones have over one thousand tester00x.tab files.
Val
What happens to the name when it hits 1000?
Do any of the names have spaces in them? If they do, this could make it a bit more difficult but can probably be done with helper batch file called REPL.bat.
Re: Sort Alphabetically Batch File needed - remove space etc
Yo Squashman.....
Sorry....the numbers actually stop at tester999.tab
and yes there is 1 space between every "tester00x.tab" just as shown in my first post:
tester001.tab tester002.tab etc etc
If you know how,please give an example of the batch file or vbs file to do this.
Thanks!
Val <- noob at this
Sorry....the numbers actually stop at tester999.tab
and yes there is 1 space between every "tester00x.tab" just as shown in my first post:
tester001.tab tester002.tab etc etc
If you know how,please give an example of the batch file or vbs file to do this.
Thanks!
Val <- noob at this
Re: Sort Alphabetically Batch File needed - remove space etc
What I meant was there any spaces in the names.
test 001.tab
test 001.tab
Re: Sort Alphabetically Batch File needed - remove space etc
Well I am sure someone will come along with a batch way to do it but I worry about the line length being to long for pure batch.
So here is how I do it in vbscript. This just replaces the space with a CRLF. Might be safer to just replace ".tab" with ".tab"VBCrLF.
So here is how I do it in vbscript. This just replaces the space with a CRLF. Might be safer to just replace ".tab" with ".tab"VBCrLF.
Code: Select all
Const ForReading = 1, ForWriting = 2
Dim fs, txt, contents
Set fs = CreateObject("Scripting.FileSystemObject")
Set txt = fs.OpenTextFile("MyFile.txt", ForReading)
contents = txt.ReadAll
txt.Close
contents = Replace(contents, " ", vbCrLF)
Set txt = fs.OpenTextFile("MyFile.txt", ForWriting)
txt.WriteLine contents
txt.Close
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Sort Alphabetically Batch File needed - remove space etc
Max line length in pure batch is 8192, right? Each filename plus space is 14 characters, so there could only be 585 files on a line and val5662 has already said that there will be over a thousand.
Re: Sort Alphabetically Batch File needed - remove space etc
As Squashman said, repl.bat is good for this particular task.
This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
Code: Select all
type file.txt | repl " " "\r\n" x >newfile.txt
This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
Re: Sort Alphabetically Batch File needed - remove space etc
I always forget that you can pipe input to repl. That is much easier using that.
Re: Sort Alphabetically Batch File needed - remove space etc
Yo guys....
Thanks for the help.
The only idea here that worked was Squashman's VBS thingy.
Thanks!
Val
Thanks for the help.
The only idea here that worked was Squashman's VBS thingy.
Thanks!

Val
Re: Sort Alphabetically Batch File needed - remove space etc
Foxidrive's solution should work as well.
Re: Sort Alphabetically Batch File needed - remove space etc
Squashman wrote:Foxidrive's solution should work as well.
Now it should. I typed the wrong slashes into it.
