2007-02-06

awk notes

$NF is the last field in an awk statement. $0 is a reference to all of the fields. Simple math can be done against the $NF variable.

$ ls -al /etc/ | awk '$NF ~ /bashrc/ {print $0}'
-rw-r--r-- 1 root root 1437 Jan 31 2006 bashrc

$ ls -al /etc/bashrc | awk '{print $(NF - 3), $(NF - 2)}'
Jan 31

No comments: