Skip to main content

How to format automatically top output for logging?

Currently my top command output is shown as:

14861 root      20   0  0.252t 0.028t    556 S  13.3 92.8   8:45.64

I want the display of this in m. It is presently showing in t. I am getting the above output with the below command:

top -b -p 14861 -n1 |tail -1

Is there any option to achieve the same. I will be writing this top output to a log using for loop. So I will not be able to do anything manually.

I even tried with small letter e, that doesn't convert for some of the processes.