|
is a “pipe.” The |
takes the standard output of the command on the left, and pipes it as standard input to the command on the right. You can think of this as “command to command” redirection.
$ cat volcanoes.txt | wc
Above, the output of cat volcanoes.txt
becomes the standard input of wc
. In turn, the wc
, “word count”, command outputs the number of lines, words, and characters in volcanoes.txt, respectively.
$ cat volcanoes.txt | wc | cat > islands.txt
Multiple |
s can be chained together. Here the standard output of cat volcanoes.txt
is “piped” to the wc
command. The standard output of wc
is then “piped” to cat
. Finally, the standard output of cat
is redirected to islands.txt
.
You can view the output data of this chain by typing cat islands.txt
.
Instructions
Let’s try some more redirection commands. In the terminal, type:
cat volcanoes.txt | wc
(Tip: If you are unable to type |
, you can find help here.)
Type:
cat volcanoes.txt | wc | cat > volcanoes_count.txt
Use cat
to output the contents of volcanoes_count.txt. Notice that three numbers appear as the output.