using cut to extract the output of top

I wanted to profile the memory usage of one of my program for different problem sizes. I was interested in only the resident memory used while the program was running . “top” was an obvious choice and luckily top provides a column in its output called RES — Resident size (kb) i.e The non-swapped physical memory a task has used. RES = CODE + DATA.

I am interested only in this column for a particular program. so I come up with two one liners and here they are

top -u ga | grep 'laplace.out' | cut -c 30-35

where -u ga is the user name which is ga in this case and I am only interested in testing .out so grep serves the pupose. after counting the output location of RES from the first charcter it was found to be at 30 to 35 so ‘cut ‘ is used for that purpose

But then I realised that awk is a better alternative then cut here is it

top -u ga |grep laplace.out |awk ‘{print $6 $12}’

so this will get me column 6 and column 12 from the top ouput

Ready to be added in the script. 🙂

This entry was posted in Administration, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s