Input/Output Processing#
Command |
Action |
---|---|
|
Output files to |
|
Sort the lines in a file |
|
Remove repeated lines |
|
Search for patterns in a file |
|
Count the lines, words and characters in a file |
|
Output the first lines of a file |
|
Output the last lines of a file |
|
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
.