tags:

views:

29

answers:

2

Suppose I have a ps command that looks like this:

ps -Ao args:80,time,user --sort time 

It will give me a "space" separated set of rows. A row might look like this

paulnath -bash 00:00:00

I would like to convince ps to delimit by commas(or tabs even!), such that it can be processed automagically by other languages. Please note that args will probably have spaces in it, so, awking by field won't per se work.

A: 

You might want to get the information you need from /proc/[0-9]*/. I think you'll find it more programmatically accessible than the output of ps.

Slartibartfast
A: 

How about:

ps -Ao args:80,time,user --sort time | 
sed 's/\([[:digit:]]\{2\}:\)\{2\}[[:digit:]]\{2\}/,\0,/'

This is sensitive to the format, including the time, and assumes processes don't have commas. They can, but if you want to escape that it's obviously more complicated.

Matthew Flaschen
Leave the command line at the end, otherwise, if the command line contains some `,` it will be hard to parse :)
Nicolas Viennot