Skip to content

Latest commit

 

History

History
66 lines (51 loc) · 917 Bytes

File metadata and controls

66 lines (51 loc) · 917 Bytes

awk

awk

NAME

awk - pattern-directed scanning and processing language

SYNOPSIS

awk [ -F fs ] [ -v var=value ] [ 'prog' | -f progfile ] [ file ... ]

EXAMPLES

  • 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
$
  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