How do i replace [] brackets using SED

后端 未结 5 1699
予麋鹿
予麋鹿 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 04:03

    Can be handled using the regex capture technique too (Eg: here below) :

    echo "narrowPeak_SP1[FLAG]" | sed -e 's/\[\([a-zA-Z0-9]*\)\]/_\1/g'
    > narrowPeak_SP1_FLAG
    
    \[ : literal match to open square bracket, since [] is a valid regex
    \] : literal match to square close bracket
    \(...\) : capture group
    \1 : represents the capture group within the square brackets
    

提交回复
热议问题