0

I'd like to cut extra spaces from "ps aux" output and replace them with one space. What I do is:

ps axu | sed 's/[ ]+/ /g'

But output seems to be unchanged, I still get too much spaces between tokens.

username    4876 ... <the rest of columns ommitted>

Why this regular expression doesn't match empty space between username and pid?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

2

Because sed uses basic regular expressions (BRE), and + isn't part of them. Use s/ */ / (two spaces in the pattern part), or -E for extended regular expressions in GNU or BSD sed: sed -E 's/ +/ /g'

ilkkachu
  • 138,973