awk

if we want to exreact and print line 1 and 3 separeted by comma from file a.txt

$ awk -F":" '{ print $1 $3 }' a.txt

$1 == "fred" { print $3 }

$5 ~ /root/ { print $3 }

{

if ( $5 ~ /root/ )

{

print $3

}

}

Number of fields

NF == 3 { print "this particular record has three fields: " $0 }

Record number

(NR < 10 ) || (NR > 100) { print "We are on record number 1-9 or 101+" }

{

#skip header

if ( NR > 10 )

{

print "ok, now for the real information!"

}

}

extract MAC address using ifconfig

ifconfig |grep -n 'HWaddr' | awk '{ print $5}'

SNR. for WIFI

iwconfig | grep -n 'Tx-Power' | awk '{ print $5}'|cut -c 10-

get PID

ps -e| grep 'name_of_process'| awk '{print $1 $4}'

get ip

ifconfig | grep 'inet addr:192'|awk '{ print $2}'|cut -c 6-

sed

s: substitution

fibonacci series

awk 'BEGIN {a=1;b=1; while(++x<=1000){print a; t=a;a=a+b;b=t}; exit}'