Page Actions
Wiki Actions
User Actions
Submit This Story

How To Wrap Awk in Shell?

I have a issue that haunts me these days. I would like a command that get HBA info from AIX. And with WWPN colonfied. I use an awk now, Awk can be a hell when embedding awk in it… All the colons, dollars issue… I'm confused on how to escape them…

The Awk

# Usage: lshba() {lsdev -F "name status physloc" | awk -f lshba.awk}
$1 ~ /^fcs.+/ {printf "%s\t%s\t",$1,$3;system("lscfg -vl "$1" | awk -F'.' \'NF == 14 {printf(\"%s\t\", $NF); for (i=1; i<16; i=i+2) { str = sprintf(\"%s:%s\", str, substr($NF, i, 2)) } printf( substr(str, 2)) }\'");print "\t"$2;}

Indention was taken out since I was hoping I can make a one-liner wrapped in shell as a function or alias but, It turned out to be very troublesome… Too much I need to escape… A hell full of colons.
I do have an awk calling sed solution, given by a friend. But the pure awk is fun and seems hard to wrap. Maybe pure ksh?

alias lshba='lsdev -F "name status physloc" -l fcs*|awk '\''{printf "%s\t%s   ",$1,$3; system("lscfg -vl "$1"|grep Network|sed -e \"s=.*\\.==;s=\\(.\\{2\\}\\)=\\1:=g;s=:$==\"|tr -d \"\n\""); print "   "$2}'\'''

And to just colonfy, I have a simple sed work around:

alias colonfy="sed -e :it -e 's/\(.*[0-9A-Za-z]\)\([0-9A-Za-z]\{2\}\)/\1:\2/;tit' <<< "
# .or. more general function solution
colonfy () { echo "$1"  | sed -e :it -e 's/\(.*[0-9A-Za-z]\)\([0-9A-Za-z]\{2\}\)/\1:\2/;tit';}

Sed is easier to embed since it doesn't rely on colons and dollars. Anyone bored enough to hack on Awk??

Discussion

Enter your comment
 
 
blog/2011/04/how_to_wrap_awk_in_shell.txt · Last modified: 2011/04/19 23:40 by MeaCulpa     Back to top
Recent changes RSS feed Creative Commons License Powered by PHP Driven by DokuWiki