Learn
Redirection
sort
$ 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.

Instructions

1.

A few commands are particularly powerful when combined with redirection. Let’s try them out.

First, use cat to view the contents of lakes.txt.

2.

Sort the contents of lakes.txt.

3.

Then type:

cat lakes.txt | sort > sorted-lakes.txt
4.

Use cat to output the contents of sorted-lakes.txt.

Folder Icon

Sign up to start coding

Already have an account?