INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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 ?

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

Try forcing a numerical output by...

CODE

nawk '{if (NR==2) print $NF+0}'] 

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

just curious if running swap -l;swap -l;swap -l;swap -l;swap -l will print the same lines

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close