Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I sort a file then output it into another file I never created or do I have to create the file I want to put in. Might not make sense how I am typing it so...

Let's say the file I have is called Names.txt. Within Names.txt is a list of names. Now I want to sort Names.txt in a reverse sort then output it to a new file called SortedNames.txt all in one command.

Or do I have to create SortedNames first, then sort it, copy what's inside names.txt then paste it on sortednames.txt?

share|improve this question

To sort Names.txt in a reverse sort order and output it into SortedNames.txt:

sort -r Names.txt > SortedNames.txt

The file SortedNames.txt does not have to exist. If it does exist and you have write-permission to that file, the command above will overwrite its contents.

The sort command has many more options.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.