Sort Alphabetically Batch File needed - remove space etc....

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Sort Alphabetically Batch File needed - remove space etc....

#1 Post by val5662 » 29 May 2014 10:46

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

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Sort Alphabetically Batch File needed - remove space etc

#2 Post by Squashman » 29 May 2014 11:36

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.

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Re: Sort Alphabetically Batch File needed - remove space etc

#3 Post by val5662 » 29 May 2014 12:59

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

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Sort Alphabetically Batch File needed - remove space etc

#4 Post by Squashman » 29 May 2014 13:12

What I meant was there any spaces in the names.

test 001.tab

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Sort Alphabetically Batch File needed - remove space etc

#5 Post by Squashman » 29 May 2014 13:22

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.

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

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Sort Alphabetically Batch File needed - remove space etc

#6 Post by ShadowThief » 29 May 2014 17:30

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Sort Alphabetically Batch File needed - remove space etc

#7 Post by foxidrive » 29 May 2014 20:06

As Squashman said, repl.bat is good for this particular task.

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.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Sort Alphabetically Batch File needed - remove space etc

#8 Post by Squashman » 30 May 2014 06:06

I always forget that you can pipe input to repl. That is much easier using that.

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Re: Sort Alphabetically Batch File needed - remove space etc

#9 Post by val5662 » 02 Jun 2014 15:18

Yo guys....
Thanks for the help.
The only idea here that worked was Squashman's VBS thingy.
Thanks! :D
Val

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Sort Alphabetically Batch File needed - remove space etc

#10 Post by Squashman » 02 Jun 2014 15:47

Foxidrive's solution should work as well.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Sort Alphabetically Batch File needed - remove space etc

#11 Post by foxidrive » 02 Jun 2014 18:17

Squashman wrote:Foxidrive's solution should work as well.


Now it should. I typed the wrong slashes into it. :oops:

Post Reply