1

I read in a textbook that sort command accepts input either from a file named on the command line or from standard input. I know about cat command accepting stdin:

$ cat
stdin
stdin

What can be an example of it with sort command?

2 Answers 2

5

In exactly the same way

$ sort
abc
xyz
def
Ctrl+D
abc
def
xyz

More often though, it would be used with a pipe

somecommand-that-produces-unsorted-output | sort
4
printf "omega\r\nbeta\r\nalpha\r\n" | sort  

alpha  
beta  
omega  

A use case would be if you wanted to sort output from any given command after a lot of cut, split, whatever.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .