Friday, February 3, 2012

Print PS output using AWK

ps aux | grep -v grep | grep apache2 | awk '{printf $1","$2","$3","$4","$5","$6","$7","$8","$9","$10"," ; for(i=11;i<=17;i++){printf "%s%s",sep,$i;sep=FS} print ""}'
root,2284,0.0,0.1,203544,9176,?,Ss,Feb02,0:00,/usr/sbin/apache2 -k start  
www-data,2398,0.0,0.1,205544,8236,?,S,Feb02,0:00, /usr/sbin/apache2 -k start  
www-data,2399,0.0,0.1,205544,8236,?,S,Feb02,0:00, /usr/sbin/apache2 -k start  
www-data,2400,0.0,0.1,205544,8236,?,S,Feb02,0:00, /usr/sbin/apache2 -k start  
www-data,2401,0.0,0.1,205544,8236,?,S,Feb02,0:00, /usr/sbin/apache2 -k start  
www-data,2402,0.0,0.1,205544,8236,?,S,Feb02,0:00, /usr/sbin/apache2 -k start

TIME,USER,PID,%CPU,%MEM,VSZ,RSS,TTY,STAT,START,TIME,COMMAND

No comments:

Post a Comment