linux · medium
Text Processing — grep, awk, sed, pipes & xargs
Command-line text processing: grep (-r/-I/-n/-o/-c), pipes and the 2>&1 ordering trap, awk for column aggregation, sed -i for substitution, and the universal sort | uniq -c | sort -rn count-and-rank pipeline.
🔑 Key line
grep -rIn / -o / -c to search. Streams: > truncate, >> append, 2>&1 (after >) merges stderr. awk for columns ({sum+=$N} END), sed -i for substitution. Universal idiom: sort | uniq -c | sort -rn = count & rank.
The code
grep -rIn 'error' /var/log/ # recursive, line nums, skip binariesgrep -oE 'feed:[0-9]+' f # print only the match
cmd > out 2>&1 # stdout + stderr to a file
awk '{sum+=$10} END{print sum}' f # sum a columnsed -i 's/old/new/g' f # in-place substitute
# The universal count-and-rank pipelineawk '{print $1}' f | sort | uniq -c | sort -rn | headWhat this lesson walks through
- 01grep: find lines fast
- 02Pipes & the 2>&1 order trap
- 03The count-and-rank pipeline
grep -rIn searches recursively with line numbers; -o extracts just the match, -c counts, -v inverts.
See it animated — step by step, at your own pace
Unlock the full interactive walkthrough of Text Processing — grep, awk, sed, pipes & xargs and 100+ animated C++ interview lessons.