Format Top and prstat command output

need help with formatting output of command top and prstat. My requirment is to remove few columns and display remaining . But when i used awk to do that the output seems to be have gone vague, mixing the column values.

After using awk to print particular column the output seems to have lost the proper column format.

$ prstat 1 1 | awk '{print $1,$2$9,$10}'
PID USERNAMECPU PROCESS/NLWP
14678 pjain60.1% ssh/1
22543 kkarun0.1% ssh/1
17455 nprak10.1% prstat/1
17331 root0.1% sshd/1
9668 tsaha10.1% sshd/1

try using printf. :slight_smile:

prstat 1 1 | awk '{printf ("%10s %10s %10s %10s\n",$1,$2,$9,$10)}'
1 Like