Hi,
I've got a big problem that makes me crazy. By using the command : ps -efo user,tty,pid,ppid,pcpu,cpu,etime,time,args
I would like to forma the result as below
Process User TTY PID PPID %CPU C START TIME Command
------- ---- --- --- ---- ---- - ----- ---- -------
I use awk for that and here is the code
ps -efo user,tty,pid,ppid,pcpu,cpu,etime,time,args | tail +2 | awk 'BEGIN {
fmt="%-40s %-10s %-9s %-9s %-9s %-9s %-9s %-9s %-9s\n"
printf fmt, "Command", "User","Terminal","PID","PPID","%CPU","C","START","Time"
trt=sprintf(fmt,"-----------------","--------","---------","---------","-------"
,"-------","-------","-------","-------")
printf trt
}
{ fmt="%-40s %-10s %-9s %-9s %-9s %-9s %-9s %-9s %-9s\n"
printf fmt,$9,$1,$2,$3,$4,$5,$6,$7,$8
}'
But because of the column "Command" format, which can include more than 1 argument with spaces, awk think there is more than one argument.
How can i get the entire argument from the 8th one? Or do you think about an alternative solution??
Thankx!!
I've got a big problem that makes me crazy. By using the command : ps -efo user,tty,pid,ppid,pcpu,cpu,etime,time,args
I would like to forma the result as below
Process User TTY PID PPID %CPU C START TIME Command
------- ---- --- --- ---- ---- - ----- ---- -------
I use awk for that and here is the code
ps -efo user,tty,pid,ppid,pcpu,cpu,etime,time,args | tail +2 | awk 'BEGIN {
fmt="%-40s %-10s %-9s %-9s %-9s %-9s %-9s %-9s %-9s\n"
printf fmt, "Command", "User","Terminal","PID","PPID","%CPU","C","START","Time"
trt=sprintf(fmt,"-----------------","--------","---------","---------","-------"
,"-------","-------","-------","-------")
printf trt
}
{ fmt="%-40s %-10s %-9s %-9s %-9s %-9s %-9s %-9s %-9s\n"
printf fmt,$9,$1,$2,$3,$4,$5,$6,$7,$8
}'
But because of the column "Command" format, which can include more than 1 argument with spaces, awk think there is more than one argument.
How can i get the entire argument from the 8th one? Or do you think about an alternative solution??
Thankx!!