$ sort continents.txt
sort takes the standard input and orders it alphabetically for the standard output (it doesn’t change the file itself). Here, the continents in continents.txt will be listed in alphabetical order:
Africa Antarctica Asia Australia Europe North America South America
$ cat glaciers.txt | sort > sorted-glaciers.txt
Here, the command takes the standard output from
cat glaciers.txt and “pipes” it to
sort. The standard output of
sort is redirected to a new file named sorted-glaciers.txt.
A few commands are particularly powerful when combined with redirection. Let’s try them out.
cat to view the contents of lakes.txt.
Sort the contents of lakes.txt.
cat lakes.txt | sort > sorted-lakes.txt
cat to output the contents of sorted-lakes.txt.