Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to retrieve the cpu usage/free percentage from mpstat output. The bash cut can be used to retrieve such details but i dont know what should be the delimiter viz.

[idlecool@archbitch proc]$ mpstat | grep "all" | cut -d '$x' -f11

what should be $x so that i can skip white spaces and select value corresponding to %idle?

Output of mpstat:

[idlecool@archbitch proc]$ mpstat 
Linux 2.6.36-ARCH (archbitch)   01/14/11    _i686_  (2 CPU)

19:58:53     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
19:58:53     all    5.51    0.01    2.96    0.84    0.00    0.01    0.00    0.00   90.66
share|improve this question
up vote 2 down vote accepted

Wrong tool.

mpstat | awk '$2 == "all" { print $11 }'
share|improve this answer

The delimiter should be space. However, mpstat uses multiple spaces between printed fields for alignment. Therefore you also need tr to squeeze multiple delimiters.

mpstat | grep -F all | tr -s ' ' | cut -d ' ' -f 11

Note: -F flag for grep is not essential in this case, though, I habitually use it whenever the pattern is not a regex as it significantly speeds up searches on big inputs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.