AWK Sample
I always consider the term “shell scripting” to be differed based on personal-state.
I found myself becoming a huge fan of awk… My shell functions tend to put heavy operations in awk…
I tend to put heavy work on utils like sed, awk, even python, not in shell itself.
lshba
This is a POSIX Shell funciton that lists HBAs in an AIX system.
lshba () { lsdev -F "name status physloc" | /usr/bin/env awk 'BEGIN { # Header print "name\tstatus\t\tphyslot\t\t\t\tWWPN\t\t\tPart #\tCCIN\tColoned WWPN"; } $1 ~ /^fcs.+/ { # Name, Status, Physlot printf "%s\t%s\t%s\t",$1,$2,$3; cmd = "lscfg -vl "$1; while ((cmd | getline) > 0){ FS="."; if (NF==18||NF==6){ # Part Number, CCIN s = s"\t"$NF; } if (NF==14){ # WWPN printf "%s", $NF; # Colonfy for (i=1; i<16; i=i+2){ str = sprintf("%s:%s", str, substr($NF, i, 2)) }; printf("%s\t%s\n", s, substr(str, 2)); s=str="" } } close(cmd); FS=" "; } '; }
This features awk's robust filtering, C-like operators, pipeline… This is NAWK variant in AIX. Old but still quite useful. Just a showcase of how elegence awk can be…And handy syntax highlighting of dokuwiki!

Discussion