List contents of text file in alphabetical order?

2

I have a txt file with about 3000 name entries on each line. I want to list them in alphabetical order.

Is there any way I can do this via some text editor so that i don't have to manually go through all the names in the list?

Jalle

Posted 2010-04-02T00:06:39.203

Reputation: 21

Answers

1

You can use a simple command that's included with Windows XP (as that's what I'm assuming you're running from your tag) called sort.

It's as simple as running sort FileToSort.txt /o OutputFile.txt in cmd [replacing FileToSort.txt with the file you want sorted and OutputFile.txt with the name of the file you want to output] (start -> run -> cmd; see here for more examples and usage).

squircle

Posted 2010-04-02T00:06:39.203

Reputation: 6 365

You know, I have been using Windows for years and years. I knew about the Unix sort command, uniq, etc. but never once thought to try it on Windows! – Joshua – 2010-04-02T00:59:31.380

"sort in.txt out.txt" doesn't work. You'll need to use "sort in.txt /o out.txt" or "sort in.txt > out.txt" – Bavi_H – 2010-04-02T01:07:02.100

@Bavi_H: Thanks, answer revised to reflect your comment. – squircle – 2010-04-02T15:12:52.600

1

PSPad has a line sorting feature: Edit -> Sort...

ConTEXT has a similar sorting feature.

Or if you can cope with Vim, that has a built-in sort command which works on a range of lines, or on the selected text.

njd

Posted 2010-04-02T00:06:39.203

Reputation: 9 743

0

If you want to write a program...

pseudocode (assumes each name is on its own line):

names as List of Strings
while(!file.eof)
{
    names.Add(file.readline());
}

names.Sort();

Steven Evers

Posted 2010-04-02T00:06:39.203

Reputation: 659

this would be a better fit if the question were asked on SO. just a thought. – squircle – 2010-04-02T00:28:14.207