Goal
Turn messy logs into clear answers using grep/awk/sed and a few patterns you will reuse forever.
grep (search)
grep -n "ERROR" app.log
grep -R "timeout" /var/log 2>/dev/null
grep -Ei "warn|error" app.log
Tips:
-n: show line number-R: recursive-E: regex-i: case-insensitive
awk (extract columns)
awk '{print $1, $2, $NF}' access.log
Common use: parse structured-ish logs.
sed (replace / clean)
sed -n '1,20p' file
sed 's/ERROR/WARN/g' file
Pipelines (the real power)
cat app.log | grep -i error | awk '{print $1,$2,$3}' | head
Exercises
- Create a file with 50 lines and some contain ERROR.
- Use grep to show only those lines.
- Use awk to print time + message.
- Use sed to remove brackets or quotes.
Production habit
Always save the useful pipeline as a snippet. That is how you build personal runbooks.
Next Step
Write a small script that uses these tools to produce a clean health report.