codeaprendiz.github.io

DevOps Essentials

View on GitHub

awk

NAME

awk - pattern-directed scanning and processing language

SYNOPSIS

awk [ -F fs ] [ -v var=value ] [ ‘prog’ -f progfile ] [ file … ]

EXAMPLES

$ awk ' {print $1,$3} '
this is one
this one
this is one two
this one
^C
$ 
$ awk ' /'pattern'/ {print $2} '
this is first line
this is line containing pattern
is
patter at first
pattern at first
at
^C
$
$ awk "BEGIN { print \"Hello, world\" }"
Hello, world
$
  1. 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
$
  1. Extract first and last column of a text file
awk '{print $1, $NF}' filename