AWK

AWK -


 * awk '{print $1}' names.txt - prints first argument
 * awk '{print $2,$1}' names.txt - prints first second argument and then the first one

awk '{print NR, $0}' dukeofyork.txt - record number

awk '{print NF, $0}' dukeofyork.txt - number of fields

awk 'NF==6{print NF,$0}' dukeofyork.txt - where record number is six

awk '{$2="TWO"; print}' dukeofyork.txt - replace second field with TWO

awk '{print NR, FILENAME, FNR, $0}' dukeofyork.txt names.txt

awk '{print $NF}' dukeofyork.txt - print last fields of the line

awk '{print $(NF-1)}' dukeofyork.txt - minus 1

awk'{a=1;b=3; print a + b }' = 4

awk'{a=1;b=3; print a b }' = 13

awk'{a=1;b=3; print a + b }'

awk '$4 ~ /up/{print}' dukeofyork.txt - print records where on fourth field we can find up

awk 'BEGIN{FS=","} {print $2}' - print second argument, after comma - FS as a field separator

awk 'BEGIN{RS="!";FS=","} {print $2}' onebigline.txt  - RS as a record separator

awk 'BEGIN{RS="";FS="\n"} {name=$1;address=$2;citystatezip=$3;print name "," adress "," citystatezip}' multiaddress.txt

awk 'BEGIN{OFS=", ";ORS="!"} {print $2,$1}' names.txt

awk -F, '{print $1 "\t" $2 "\t" $3}' nameemailavg.csv - comma as separator in orginal file