Code-Memo

Text processing (grep, awk, sed)

grep -n "ERROR" app.log
grep -RIn "TODO" .
grep -E "^(GET|POST) " access.log

Useful flags:

awk (structured text)

Common for columnar output:

df -h | awk 'NR==1 || $5+0 > 80 {print}'
ps aux | awk '$3 > 50 {print $1, $2, $3, $11}'

Patterns:

sed (stream editing)

sed -n '1,20p' file.txt
sed 's/foo/bar/g' file.txt
sed -E 's/[[:space:]]+$//' file.txt

In-place editing (GNU sed):

sed -i 's/old/new/g' file.txt

Pipelines (composition)

journalctl -u ssh --no-pager | grep -i "failed" | awk '{print $1,$2,$3,$NF}' | sort | uniq -c | sort -nr

Tips