# awk reference - text processing for tabular data

records: 
default - line

fields:
default - separated by whitespace character

awk '<pattern>'
awk '{ <action> }'
awk '<pattern> { <action> }'

types:
    * string
    * number

# awk program
awk -f progfile <optional list of input files>


echo 'hello universe this is saran' | awk '{print $1,$5}'
echo 'hello universe this is saran' | cut -d ' ' -f 1,5

echo 'ajay manager account 50000
satvik director purchase 80000' | awk '{print}'

echo 'ajay manager account 50000
satvik director purchase 80000' | awk '{print $4}'

echo 'ajay manager account 50000
satvik director purchase 80000' | awk '/manager/ {print}'

# $0 - entire line
echo 'hello universe' | awk '{print $0}'

# NR - number of records
echo 'ajay manager account 50000
satvik director purchase 80000' | awk '{print NR}'

echo 'ajay manager account 50000
satvik director purchase 80000' | awk '{print NR,$0}'

# NF - number of fields
echo 'ajay manager account 50000
satvik director purchase 80000' | awk '{print NF}'

echo 'ajay manager account 50000
satvik director purchase 80000' | awk '{print $1,NF}'

# $NF - last value
echo 'ajay manager account 50000
satvik director purchase 80000' | awk '{print $1,$NF}'

echo 'ajay manager account 50000
satvik director purchase 80000' | awk '{print NR " - " $1}'

# BEGIN & END
echo 'ajay manager account 50000
satvik director purchase 80000' | awk 'BEGIN {print NR}'

echo 'ajay manager account 50000
satvik director purchase 80000' | awk 'END {print NR}'

# -F can take regex '[-,/]'
echo 'ajay/manager/account/50000
satvik/director/purchase/80000' | awk -F/ '{print NR}'

echo 'ajay/manager,account-50000
satvik,director/purchase-80000' | awk -F'[-,/]' '{print NR}'
