0

Hi I have a command that produces the following:

/usr/ucb/ps -auxxx|awk '{print $3,$4,$2,$1,$11}'|grep -v 0.0
%CPU %MEM PID USER COMMAND
0.2 5.217405286920 1910 noaccess
0.1 0.1 180 root 0:43
0.1 0.1 686 root 0:41
0.1 0.1 26198 chris /usr/lib/ssh/sshd
0.1 0.1 26767 root /usr/ucb/ps
0.1 0.1 26215 root bash
0.1 0.1 26765 root sleep
0.1 0.1 26766 root sleep

I need it to make the first two colums to two decimal places i have tried for ages and cant seem to crack it any help?

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Fest3er
0

yes I tired that but could only get the ouput to follow one line after the other and not stay in the columns can you give me the code please?

0

Try this and see if you can figure out:

echo "2.3 4.56789" | awk '{printf "%.2f %.2f\n", $1, $2}'
0
/usr/ucb/ps -auxxx | awk '{printf("%4s %4s %5s %4s %s\n", $3,$4,$2,$1,$11)}' | grep -v 0.0

probably does what you really want: line up the columns. If you truly want the numbers to be %5.2f format, you'll need to treat the column heading line differently.

Another option that might work:

ps -eo '%cpu %mem pid user comm' --sort user,pid | grep -v 0.0

if you just want certain data from ps() (and sorted on one or more fields).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.