0

Is there an option I can use in this command to return each result on a new line instead of just separated by a space?

echo $(ps ax | awk '/usr/ {print $5}')
user3299633
  • 2,473
  • 2
  • 21
  • 38

2 Answers2

0
awk 'BEGIN{while("ps ax"|getline){if($5~/^\/usr\//){print $5}}}'

alternative approach

 ps -ax|awk '{if($5~/^\/usr\//){print $5}}'
repzero
  • 7,924
  • 2
  • 14
  • 38
0

The proper way to do it is simply:

ps ax | awk '/usr/ {print $5}'

If you want to keep your original form with echo (but I think it's pointless), then you'd have to quote the subshell result:

echo "$(ps ax | awk '/usr/ {print $5}')"

Paul
  • 18,575
  • 6
  • 53
  • 71