why am I getting spaces in sed 's/[a-z]*/(&)/g'

后端 未结 3 1612
甜味超标
甜味超标 2021-01-16 04:28

I want to add parenthesis to all words I used

sed \'s/[a-z]*/(&)/g\' 

inputfile.txt

hola crayola123456
abc123456
         


        
3条回答
  •  梦毁少年i
    2021-01-16 04:55

    Two errors:

    1. * means 0 or more matches, you need at least one match, then +;
    2. sed (OSX version) uses basic regexp by default (so + isn't available), you should activate extended regexp syntax with option -E.

    Then:

    echo "hola abc1234 foo12 bar" | sed -E 's/[a-z]+/(&)/g'
    

    produces:

    (hola) (abc)1234 (foo)12 (bar)
    

提交回复
热议问题