Text Processing Power-Ups
Systems engineers spend a lot of time analyzing logs. The "Big Three" tools are essential.
Grep (Global Regular Expression Print)
Used to search text for patterns.
# Find errors in a log file
grep "ERROR" /var/log/syslog
# Find errors, ignoring case
grep -i "error" /var/log/syslog
Sed (Stream Editor)
Used primarily for find and replace operations.
# Replace 'foo' with 'bar' on every line
sed 's/foo/bar/g' file.txt
Awk
A full programming language used for extracting fields/columns from structured data.
# Print the first and third columns of a CSV
awk -F',' '{print $1, $3}' data.csv
booting...