This is a draft cheat sheet. It is a work in progress and is not finished yet.
Options
awk '{print}' file # cat
# script file, -f
echo "{print}" > cmd.txt
awk -f cmd.txt file
# pretty-printed script file
awk --profile
cat awkprof.out
# variables (before any block), -v
awk -v x=3 'BEGIN {printf "x=%i\n", x}'
# dump variables
awk --dump-variables ''
cat awkvars.out
|
Basics
# printing specific columns
awk '{print $3" \t" $4}' # 3rd and 4th columns
# print with pattern matching
awk '/pattern/ {print $0}' # or simply print
# count pattern
awk '/a/(c++) {} END {printf "Count=%i\n", c}'
# length()
awk 'length($0) > 10' # print lines > 10 char
|
|
|
|
|
|