Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk bug in Solaris 10? awk and nawk return incorrect integer in $NF

Status
Not open for further replies.

am115998

Technical User
Feb 4, 2016
1
GB
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 ?
 
Try forcing a numerical output by...

Code:
nawk '{if (NR==2) print $NF+0}']
 
just curious if running swap -l;swap -l;swap -l;swap -l;swap -l will print the same lines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top