Why regular expression doesn't match input with sed command

Wojciech Wirzbicki

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?

ilkkachu

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'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why my regular expression doesn't match this?

From Dev

Why doesn't regular expression alternation (A|B) match as per doc?

From Dev

sed command with regular expression

From Dev

Regular Expression doesn't Match with string

From Dev

Java Regular Expression doesn't find a match

From Dev

Why this Regular Expression doesn't work?

From Dev

sed replace regular expression match

From Dev

understand Regular expression in a sed command

From Dev

Regular expression for replacing numbers doesn't work with 'sed'

From Dev

Regular expression for replacing numbers doesn't work with 'sed'

From Dev

Regular Expression Match to Extract Command

From Java

Regular expression to match a line that doesn't contain a word

From Dev

Regular expression for word that doesn't match a list of words

From Dev

Regular expression with named subpattern doesn't see the best match

From Dev

Match line that doesn't end with >\s* using regular expression

From Dev

Regular Expression to match string which doesn't contain substring

From Dev

Regular expression to match text that "doesn't" contain a word?

From Dev

Use of Java regular expression, doesn't match *.jpg or *.gif

From Dev

Why does this regular expression match?

From Dev

Why doesn't '[0-9]*' match 'abc' in my Python regular expression since there are zero or more digits in the string?

From Dev

Why doesn't '[0-9]*' match 'abc' in my Python regular expression since there are zero or more digits in the string?

From Dev

How to match everything but a regular expression with sed?

From Dev

How to match everything but a regular expression with sed?

From Dev

why the ls -R (recursing down) doesn't work with regular expression

From Dev

why the ls -R (recursing down) doesn't work with regular expression

From Dev

Why doesn't the '?' regex character produce a match in sed?

From Dev

Regular expression not matching correctly in sed command

From Dev

Why my sed command doesn't work sometimes with the r flag

From Dev

Why the 'stop' pattern doesn't work in my sed command?

Related Related

  1. 1

    Why my regular expression doesn't match this?

  2. 2

    Why doesn't regular expression alternation (A|B) match as per doc?

  3. 3

    sed command with regular expression

  4. 4

    Regular Expression doesn't Match with string

  5. 5

    Java Regular Expression doesn't find a match

  6. 6

    Why this Regular Expression doesn't work?

  7. 7

    sed replace regular expression match

  8. 8

    understand Regular expression in a sed command

  9. 9

    Regular expression for replacing numbers doesn't work with 'sed'

  10. 10

    Regular expression for replacing numbers doesn't work with 'sed'

  11. 11

    Regular Expression Match to Extract Command

  12. 12

    Regular expression to match a line that doesn't contain a word

  13. 13

    Regular expression for word that doesn't match a list of words

  14. 14

    Regular expression with named subpattern doesn't see the best match

  15. 15

    Match line that doesn't end with >\s* using regular expression

  16. 16

    Regular Expression to match string which doesn't contain substring

  17. 17

    Regular expression to match text that "doesn't" contain a word?

  18. 18

    Use of Java regular expression, doesn't match *.jpg or *.gif

  19. 19

    Why does this regular expression match?

  20. 20

    Why doesn't '[0-9]*' match 'abc' in my Python regular expression since there are zero or more digits in the string?

  21. 21

    Why doesn't '[0-9]*' match 'abc' in my Python regular expression since there are zero or more digits in the string?

  22. 22

    How to match everything but a regular expression with sed?

  23. 23

    How to match everything but a regular expression with sed?

  24. 24

    why the ls -R (recursing down) doesn't work with regular expression

  25. 25

    why the ls -R (recursing down) doesn't work with regular expression

  26. 26

    Why doesn't the '?' regex character produce a match in sed?

  27. 27

    Regular expression not matching correctly in sed command

  28. 28

    Why my sed command doesn't work sometimes with the r flag

  29. 29

    Why the 'stop' pattern doesn't work in my sed command?

HotTag

Archive