How do i replace [] brackets using SED

后端 未结 5 1676
予麋鹿
予麋鹿 2021-01-04 03:04

I have a string that i am want to remove punctuation from.

I started with

sed \'s/[[:punct:]]/ /g\'

But i had problems on HP-UX n

5条回答
  •  一整个雨季
    2021-01-04 03:44

    You need to place the brackets early in the expression:

    sed 's/[][=+...-]/ /g'
    

    By placing the ']' as the first character immediately after the opening bracket, it is interpreted as a member of the character set rather than a closing bracket. Placing a '[' anywhere inside the brackets makes it a member of the set.

    For this particular character set, you also need to deal with - specially, since you are not trying to build a range of characters between [ and =. So put the - at the end of the class.

提交回复
热议问题