Awk

From www.ReeltoReel.nl Wiki
Revision as of 15:59, 9 October 2014 by Pvdm (talk | contribs) (Created page with "=awk= pattern {action} pattern {action} $ awk '{print $2}' /etc/fstab $ awk '/^[^#]/ {print $2}' /etc/fstab to filter out comment lines - starting with # print first f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

awk

pattern {action}
pattern {action}
$ awk '{print $2}' /etc/fstab
$ awk '/^[^#]/ {print $2}' /etc/fstab

to filter out comment lines - starting with #

print first field from password file using field seperator ':'

$ awk -F: '{print$1}' /etc/passwd

print only user ID > 500

$ awk -F: '$3>=500 {print$1}' /etc/passwd

display average of numbers entereed on a line:

$ awk '{ sum=0; for (i=1; i<=NF; i++) sum +=$i; print sum/NF; }'
NF