Page 1 of 1
Sorting list in alphabetical order?
Posted: 19 Apr 2012 17:40
by MrKnowItAllxx
I have a text file that I would like to be sorted (or just displayed) in alphabetical order
Currently I am using 'for /f "tokens=* delims=" %%a in (myfile.txt) do echo %%a'
I simply want the output alphabetical, any solution is fine
Re: Sorting list in alphabetical order?
Posted: 19 Apr 2012 18:41
by foxidrive
Displayed:
Redirected into another file:
Re: Sorting list in alphabetical order?
Posted: 19 Apr 2012 20:10
by MrKnowItAllxx
Code: Select all
for /f "tokens=* delims=" %%a in ('sort <myfile.txt') do echo %%a
Output:
Code: Select all
< was unexpected at this time.
C:\Users\User\Desktop>
How could I accomplish this in this format?? The file is not organized in a way that would generate suitable output from 'sort <myfile.txt' so I was hoping I could embed this in a for loop as opposed to restructuring the whole file
![Confused :?](./images/smilies/icon_confused.gif)
Re: Sorting list in alphabetical order?
Posted: 19 Apr 2012 22:28
by Aacini
You must escape the < redirection sign:
Code: Select all
for /f "tokens=* delims=" %%a in ('sort ^<myfile.txt') do echo %%a
Note that tokens=* is not required in this case:
Code: Select all
for /f "delims=" %%a in ('sort ^<myfile.txt') do echo %%a
Re: Sorting list in alphabetical order?
Posted: 20 Apr 2012 20:14
by MrKnowItAllxx
Thank you very much Aacini and foxidrive
![Smile :)](./images/smilies/icon_smile.gif)
Problem solved