Find the answer to your Linux question:
Results 1 to 3 of 3
Hello, I want to format the output of the ps command, so that each column has a comma separating them, so when I type in the command: Code: ps aux ...
  1. #1
    Just Joined!
    Join Date
    Oct 2006
    Posts
    24

    [SOLVED] Formatting the output of the ps command

    Hello, I want to format the output of the ps command, so that each column has a comma separating them, so when I type in the command:

    Code:
    ps aux
    So one of the rows is

    Code:
    qmailr   22348  0.0  0.1  1688  356 ?        S     2008   0:00 qmail-rspawn
    I would like the row to be outputted like

    Code:
    qmailr,   22348,  0.0,  0.1,  1688,  356, ?,        S,     2008,   0:00, qmail-rspawn
    I have a php app that is processing the command, and I wanted to try and separate each column by tabs, using preg_split in php, but I couldn't get that to work, so I want to try and output the command by using commas after each column.

  2. #2
    Just Joined!
    Join Date
    Feb 2009
    Posts
    45
    Quote Originally Posted by adaykin View Post
    Hello, I want to format the output of the ps command, so that each column has a comma separating them, so when I type in the command:

    Code:
    ps aux
    So one of the rows is

    Code:
    qmailr   22348  0.0  0.1  1688  356 ?        S     2008   0:00 qmail-rspawn
    I would like the row to be outputted like

    Code:
    qmailr,   22348,  0.0,  0.1,  1688,  356, ?,        S,     2008,   0:00, qmail-rspawn
    I donʼt see why you would want to keep the white spaces. Thatʼs why I think this solution is appropriate:
    Code:
    $> ps aux | perl -pe '$_ = join(",", split /\s+/, $_, 11)'
    USER,PID,%CPU,%MEM,VSZ,RSS,TTY,STAT,START,TIME,COMMAND
    root,1,0.0,0.1,1596,548,?,Ss,10:26,0:00,init [3]  
    root,2,0.0,0.0,0,0,?,S<,10:26,0:00,[kthreadd]
    root,3,0.0,0.0,0,0,?,S<,10:26,0:00,[ksoftirqd/0]
    root,4,0.0,0.0,0,0,?,S<,10:26,0:00,[events/0]
    […]
    root,4494,0.0,2.4,33004,12336,?,Ss,10:27,0:00,/usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D LANGUAGE -D MANUAL -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D PHP5 -d /usr/lib/apache2 -f /etc/apache2/httpd.conf -k start
    […]
    
    $> ps aux
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root         1  0.0  0.1   1596   548 ?        Ss   10:26   0:00 init [3]  
    root         2  0.0  0.0      0     0 ?        S<   10:26   0:00 [kthreadd]
    root         3  0.0  0.0      0     0 ?        S<   10:26   0:00 [ksoftirqd/0]
    root         4  0.0  0.0      0     0 ?        S<   10:26   0:00 [events/0]
    […]
    root      4494  0.0  2.4  33004 12336 ?        Ss   10:27   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D LANGUAGE -D MANUAL -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D PHP5 -d /usr/lib/apache2 -f /
    […]

  3. #3
    Just Joined!
    Join Date
    Oct 2006
    Posts
    24
    Thanks, that worked!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...