awk - pattern-directed scanning and processing language
awk [ -F fs ] [ -v var=value ] [ 'prog' | -f progfile ] [ file ... ]
- Print only columns one and three using stdin
$ awk ' {print $1,$3} '
this is one
this one
this is one two
this one
^C
$
- Print only elements from column 2 that match pattern using stdin
$ awk ' /'pattern'/ {print $2} '
this is first line
this is line containing pattern
is
patter at first
pattern at first
at
^C
$
- Classic "Hello, world" in awk
$ awk "BEGIN { print \"Hello, world\" }"
Hello, world
$
- Print what's entered on the command line until EOF
$ awk '{ print }'
this is
this is
new file
new file
end now^D
end now
^C
$
- Extract first and last column of a text file
awk '{print $1, $NF}' filename