How do you use awk, sed, and grep together to parse log files?
These three tools form the backbone of Linux log analysis:
# grep: Filter lines containing "ERROR"
grep "ERROR" /var/log/app.log
# awk: Extract specific fields (e.g., column 3 of an NGINX access log)
awk '{print $3}' /var/log/nginx/access.log
# sed: Replace or transform text
sed 's/ERROR/CRITICAL/g' app.log
# Combined pipeline: Find ERROR lines, extract IP (field 1), count by IP
grep "ERROR" /var/log/nginx/access.log \
| awk '{print $1}' \
| sort \
| uniq -c \
| sort -rn \
| head -10