Text Processing
If the Pipes & Redirection section taught you how to wire commands together, this section teaches you the tools that make the wiring worth doing. Text is the common currency of Linux: configuration files, logs, command output, source code — nearly everything is plain text, and nearly everything useful is text you want to search, filter, reshape, or count.
This section covers the classic text-processing toolkit. Each command does one thing well, and together they can turn a 10,000-line log into a one-line answer. grep finds lines. sed and awk rewrite and analyze them. sort, uniq, and wc count and organize them. tr, cut, and paste reshape them character by character or column by column. tee splits a stream, and xargs turns text into arguments for other commands.
Common Text Processing Tools
| Command | What It Does |
|---|---|
grep | Search text for lines matching a pattern. |
sed | Find and replace text, edit streams line by line. |
awk | A full programming language for columnar text analysis. |
sort | Sort lines of text alphabetically or numerically. |
uniq | Report or remove duplicate lines. |
wc | Count lines, words, and characters. |
tr | Translate or delete characters. |
cut | Extract specific columns or characters from each line. |
paste | Merge lines of files side by side. |
tee | Write output to a file and the screen at the same time. |
xargs | Build and run commands from piped input. |
The Classic Pipeline
Almost every real-world text task is a pipeline built from these tools. A favorite: finding the ten most common words in a file.
cat file.txt | tr ' ' '\n' | sort | uniq -c | sort -rn | head -10
Read it left to right: split into words, sort them, collapse duplicates with counts, sort by count descending, take the top ten. Five tiny tools, one powerful result — that is the whole philosophy of this section.
Why This Matters
- Logs are unreadable without them. No one reads a 2 GB log file by eye; you
grepandawkit. - You stop editing by hand.
sedapplies the same fix to a hundred files in one command. - Counting becomes trivial. “How many errors today?” is one pipeline, not an afternoon.
- Other tools depend on them.
findwith-execusesxargs; almost every admin script usesgrep.
Learn these eleven commands and you have learned the vocabulary that the rest of the Linux world speaks.