Input/Output Processing

Command Action
cat Output files to stdout
sort Sort the lines in a file
uniq Remove repeated lines
grep Search for patterns in a file
wc Count the lines, words and characters in a file
head Output the first lines of a file
tail Output the last lines of a file
tee Split a stream like a pipe tee

Building a Pipleline

In this example I use the spell program to find misspelled words in the spellk file. The uniq program removes duplicate lines but there’s a catch, the repeated lines have to be next to each other. That’s why uniq is always paired with sort to guarantee that duplicates are on adjacent lines. Finally I use a tee to see the output and also capture it to a file.

Counting Words

The wc program gets it’s name from “word count” but it’s more frequently used to count lines.

The wc command can be useful in a pipeline. Here’s how to count all of the files in your home directory. Note how stderr from find is redirected to /dev/null to suppress error output.

Grepping for Love

The grep program looks for words inside of text files. It prints the lines where words are located. This demonstration shows the common uses of grep.