Hi,
I'm trying to print the output of the top command but I only want certain columns printed in a certain order. The problem I'm having is that I can't seem to get awk to recognise the second field of the top command (no flags) as a single column when there is a space in the command name. It treats the space as being a field delimiter.
I'm stripping out the header info for the time being and getting the top 40 processes. Its the top 40 processes that I want in the order PID, PPID, Command, State, UID, User, %CPU and Time
The processes that are listed with a space in the name are "Google Chrome" btw.
Any help with this is much appreciated.
I'm trying to print the output of the top command but I only want certain columns printed in a certain order. The problem I'm having is that I can't seem to get awk to recognise the second field of the top command (no flags) as a single column when there is a space in the command name. It treats the space as being a field delimiter.
I'm stripping out the header info for the time being and getting the top 40 processes. Its the top 40 processes that I want in the order PID, PPID, Command, State, UID, User, %CPU and Time
Code:
Top -l1 -u -o cpu -S | head -54 | tail -41 | awk ' { printf "%-6s \%-6s \%-16s \%-8s \%-3s \%-13s \%-5s \%-8s \n",$1,$15,$2,$16,$17,$28,$3,$4 }'
The processes that are listed with a space in the name are "Google Chrome" btw.
Any help with this is much appreciated.