Hi
I think this a bug in Solaris 10 Generic_150400-13 on sun4v - awk and nawk but its not consistent across systems cloned from the same sysunconfig'd Solaris 'image'. Some work. Others don't. LANG and other internationalisation/localisation settings were'nt changed. Anyway - back to awk...
Task:
2 line output from 'swap -l' -> find diff between blocks (total) and 'free' / 2048 to show actual swap content in MB
Code is: swap -l | awk ' { if ( NR==2) print $(NF-1) - $(NF) }'
...this requires the content of $NF and $NF-1 to be correct but both awk and nawk 'adjust' the value of $NF when it is an integer! Text in $NF is printed OK.
A quick check - run several times with identical results (box not busy at this time)...
> swap -l; swap -l | awk ' {if (NR==2) print $(NF)}'; swap -l | nawk ' {if (NR==2) print $(NF)}'
swapfile dev swaplo blocks free
/dev/swap 4294967295,4294967295 16 88080384 40848032
40847328
40847296
Any awk specifics I've missed w.r.t. my use of NF ?
I think this a bug in Solaris 10 Generic_150400-13 on sun4v - awk and nawk but its not consistent across systems cloned from the same sysunconfig'd Solaris 'image'. Some work. Others don't. LANG and other internationalisation/localisation settings were'nt changed. Anyway - back to awk...
Task:
2 line output from 'swap -l' -> find diff between blocks (total) and 'free' / 2048 to show actual swap content in MB
Code is: swap -l | awk ' { if ( NR==2) print $(NF-1) - $(NF) }'
...this requires the content of $NF and $NF-1 to be correct but both awk and nawk 'adjust' the value of $NF when it is an integer! Text in $NF is printed OK.
A quick check - run several times with identical results (box not busy at this time)...
> swap -l; swap -l | awk ' {if (NR==2) print $(NF)}'; swap -l | nawk ' {if (NR==2) print $(NF)}'
swapfile dev swaplo blocks free
/dev/swap 4294967295,4294967295 16 88080384 40848032
40847328
40847296
Any awk specifics I've missed w.r.t. my use of NF ?