/cheatsheets/awk cheatsheet/

awk cheatsheet


Split and get nth words
# Get 1st, 3rd, and 5th words
awk '{print $1, $3, $5}'
Split and get last nth words
# Get last 3 words
awk '{print $(NF-2), $(NF-1), $NF}'
Split by separator other than space
awk -F ';' '{print $2}'
Split by multiple characters
# Split line by ": ", using "-F" argument
awk -F ': ' '{print $2}'
Split and get word specified by bash variable
awk -v C=$COLUMN '{print $C}'
Print words and seperate by colon
awk '{print $1 ":" $2}'