Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNIX sort: Sorting something from the clipboard

The other day I saw a colleague of mine using sort to sort a number of lines he copied from a text file.

I've been trying to reproduce it myself and I cannot seem to find how.

The requirements are as follow:

  • Use sort from command line, plus whatever else you need to add to configure input

  • Paste the text to be sorted from the clipboard

  • Get the sorted result in the console

like image 986
Iker Jimenez Avatar asked Mar 12 '10 17:03

Iker Jimenez


People also ask

How do you sort the entries in a text file in ascending order?

Sort a File Numerically To sort a file containing numeric data, use the -n flag with the command. By default, sort will arrange the data in ascending order. If you want to sort in descending order, reverse the arrangement using the -r option along with the -n flag in the command.

How do you sort text in Unix?

SORT command is used to sort a file, arranging the records in a particular order. By default, the sort command sorts file assuming the contents are ASCII. Using options in the sort command can also be used to sort numerically. SORT command sorts the contents of a text file, line by line.

How do I sort in ascending order in Unix?

Option -n In Unix, when you try to sort a file in a numeric way, you can use the option '-n' with the sort command. This command is used to sort the numeric contents present in the file. Be default, it sorts in ascending order.


2 Answers

If you type sort - the command will accept input from stdin. Then you can just paste whatever you want into the console and type CTRL-D to sort it.

like image 61
Justin Ethier Avatar answered Oct 30 '22 17:10

Justin Ethier


Easy, just type sort (or sort -) to run on stdin, paste your lines, and hit CTRL+D for end-of-transmission to sort.

like image 5
ezod Avatar answered Oct 30 '22 15:10

ezod