views:

53

answers:

3

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

+1  A: 

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.

Justin Ethier
Excellent!I think that is undocumented in my man page. I've just found out that I can use it with --files0-from=- too
Iker Jimenez
Yeah, its not in my manpage either. But - is a standard UNIX convention to use stdin as input. Most standard UNIX programs will recognize it as well.
Justin Ethier
It's probably not explicitly documented for `sort` because it works for all sorts of UNIX utilities that operate on streams.
ezod
good thing to know. Thanks guys.
Iker Jimenez
+1  A: 

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

ezod
OK, so sort without params works too. Thanks. I really think the man page could be improved...
Iker Jimenez
+1  A: 

Use xclip.

 xclip -o | sort -
Sorpigal
+1! But xclip is a 3rd party tool.
ezod
Sad but true. Sometimes third party tools are the right way to go.
Sorpigal