Part 5 · 1 chapters · ~8 min
Text Tools
grep and ripgrep, regular expressions (basic, extended, PCRE), sed for substitution and ranges, awk fields, patterns and aggregation, sort, uniq, cut, tr, wc, head and tail -f, jq for JSON logs and APIs, comm and join, GNU versus BSD differences, and when to reach for Python or DuckDB instead.
6
Questions answered in one line
code
rg -n 'TODO|FIXME' --type ts # code search
grep -c ' 503 ' access.log # how many 503s
awk '{print $4}' access.log | cut -c14-15 | sort | uniq -c # requests per hour
awk '$NF > 1.0 {n++} END {print n " slow"}' access.log # count requests slower than 1 s (last field)
sed -E 's/("password":)"[^"]*"/\1"[REDACTED]"/g' dump.json # redact
tail -f app.log | grep --line-buffered ERROR # follow live
# JSON logs with jq
jq -r 'select(.level == "error") | [.ts, .route, .msg] | @tsv' app.jsonl | head
jq -s 'group_by(.route) | map({route: .[0].route, n: length}) | sort_by(-.n)' app.jsonl
curl -s https://api.github.com/repos/nodejs/node | jq '{stars: .stargazers_count, issues: .open_issues_count}'
comm -13 <(sort expected_ids.txt) <(sort actual_ids.txt) # ids present only in actualWhen a one-liner grows past a line or needs joins across large files, switch to Python, or query the files with SQL directly using DuckDB (Data Engineering P2).
TEXT TOOLS: WHICH FOR WHAT
one-liners that answer questions
swipe the figure sideways, or tap expand for full screen
1/4
find
grep -c ERROR counts; grep -o extracts matches; ripgrep searches large codebases quickly.
find linesrg for code