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,971
  • 3
  • 24
  • 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
  • 8,254
  • 2
  • 18
  • 40
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
  • 20,883
  • 7
  • 57
  • 74