Text Processing: grep, sed, awk
Advanced
Overview
grep filters lines that match a pattern. Combine it with pipes to drill into logs quickly, and use -i for case-insensitive and -r to search recursively.
sed edits streams: the s/old/new/g form does find-and-replace. awk treats each line as fields split by whitespace, perfect for columnar data like ps or CSV output.
These tools shine when chained together with | so the output of one becomes the input of the next.
Cheatsheet
grep -i error app.logCase-insensitive searchgrep -rn TODO src/Recursive search with line numberssed 's/foo/bar/g' fReplace all foo with barawk '{print $1}' fPrint the first columnawk -F, '{print $2}' fUse comma as the field separatorsort | uniq -cCount unique linesTry it
A safe, simulated terminal. Run the suggested commands to see typical output.
simulated terminal
Type a command and press Enter, or click a suggestion below to run it.
Quick quiz
1. Which command replaces every 'foo' with 'bar' in a stream?
2. By default, awk splits each line into fields based on what?