Replace Solaris vmstat numbers with human readable format

vmstat 1 10 | /usr/xpg4/bin/awk -f ph-vmstat.awk
% cat ph-vmstat.awk # Return human readable numbers function hrnum(a) { b = a ; if (a > 1000000) { b = sprintf("%2.2fM", a/1000000) ; } else if (a > 1000) { b = sprintf("%2.2fK", a/1000) ; } return(b) ; } # Return human readable storage function hrstorage(a) { b = a ; if (a > 1024000) { b = sprintf("%2.2fG", a/1024/1024) ; } else if (a > 1024) { b = sprintf("%2.2fM", a/1024) ; } return(b) ; } OFS=" " ; $1 !~ /[0-9].*/ {print} $1 ~ /[0-9].*/ { $4 = hrstorage($4) ; $5 = hrstorage($5) ; $9 = hrnum($9) ; $10 = hrnum($10) ; $17 = hrnum($17) ; $18 = hrnum($18) ; $19 = hrnum($19) ; print ; }
Sample Output
kthr      memory            page            disk          faults      cpu
 r b w   swap  free  re  mf pi po fr de sr cd cd cd s0   in   sy   cs us sy id
0   0   0   775.21M   42.10M   0   2   0   8   16   0   23   0   2   2   -0   448   703   988   2   1   98
0   0   44   35.09M   31.94M   20   540   147   302   302   0   0   311   111   107   0   1.89K   931   960   0   10   90
0   0   44   33.50M   27.88M   21   862   133   318   318   0   0   336   85   117   0   2.48K   1.16K   980   1   14   85
0   0   44   34.36M   27.76M   0   779   100   143   143   0   0   389   130   109   0   2.65K   1.05K   1.25K   0   15   84
0   0   44   33.95M   26.61M   33   830   144   444   444   0   0   434   138   115   0   3.38K   1.53K   1.42K   0   17   82
0   0   44   36.61M   26.18M   15   721   234   246   246   0   0   378   113   96   0   2.10K   1.01K   1.03K   0   11   89
0   0   44   34.71M   26.60M   6   717   186   182   182   0   0   326   93   133   0   2.43K   809   1.05K   0   15   85
0   0   44   35.71M   30.82M   43   763   159   565   565   0   0   422   112   119   0   2.46K   1.57K   1.09K   0   15   85
0   0   44   35.36M   29.56M   5   741   145   174   174   0   0   435   116   121   0   2.54K   834   1.18K   0   15   85
0   0   44   35.09M   30.14M   15   897   139   273   273   0   0   452   115   134   0   2.55K   1.15K   1.12K   0   17   82

5
By: MarcoN
2009-05-04 04:55:00

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: