Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can we extract a column from output in which whitespace is not in a regular format?

For example, when we type ps -ef, it shows all the process, process id's.... etc. How can we get only the last column or any specific column?

share|improve this question
Even if we go for ls -l in any directory the number of white spaces between the columns would be uneven. – monu Feb 26 '13 at 10:36

Using -o option you can specify what fields should be displayed. List of available fields you can find in man ps or using ps L.

For example using ps -eo user,command will display usernames and commands - something like this:

root /bin/login --
root /sbin/getty 

You can also use -O and parameters which will cause using some default fields and appending that specified by you, but if you want to parse output I will recommend o.

share|improve this answer

Maybe you want:

ps -eo comm

To get the command name or

ps -eo args

To get the command args or

ps -eo args="Last-Arg" | awk '{print $NF}'

To get the last argument.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.