Linux AWK Command Game
Linux AWK Command Cheat Sheet
- Print the first column:
awk '{print $1}' filename
- Print specific columns:
awk '{print $1, $3}' filename
- Use a custom delimiter:
awk -F':' '{print $1}' filename
- Filter rows where a column matches:
awk '$2 == "match"' filename
- Filter rows where a column is greater than:
awk '$3 > 1000' filename
- Print the last column:
awk '{print $NF}' filename
- Count the number of lines:
awk 'END {print NR}' filename
- Replace a word:
awk '{gsub(/old/, "new"); print}' filename
- Print lines where a column starts with:
awk '$1 ~ /^start/' filename
- Exclude lines containing a pattern:
awk '!/pattern/' filename