title: How do you use "top" to extract only the CPU usage and the process names (command) columns?
body: <p>I want only to extract the CPU usage column with the percentages and the process names from the output of the top command. Using this command: <code>top -b | awk '{print $NF}' &gt; output.txt</code>, I can extract the last column from top and save into a file. However this solution is insufficient since COMMAND section can span multiple columns. How to extract and print CPU% and complete COMMAND section of top output ? The output format I need is like below.</p>
  <pre><code>%CPU  COMMAND
  6.2   Xorg
  6.2   gnome-terminal
  6.2   top
  0.0   init
  0.0   kthreadd
  0.0   ksoftirqd/0
  0.0   kworker/0:0H
  0.0   kworker/u:0H
  0.0   migration/0
  0.0   rcu_bh
  </code></pre>