Generating a CSV list from Linux 'ps'

Paul Nathan picture Paul Nathan · Jun 25, 2010 · Viewed 10.6k times · Source

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.

Answer

emx picture emx · Jun 17, 2012

You can use the following syntax to put your own delimiter:

ps -Ao "%U,%t,%a"