2

I am looking for the sed command to replace text like this "[word1 word2]" to nothing.

I tried

sed -i -e 's/[Word1 Word2]//g'

It didn't work and replaced entire my text in disorder way.

I would like to request you to help me to replace special characters like these.

Thanking you, Punith.

2
  • 1
    sed -e 's/\[Word1 Word2\]//g' Feb 15, 2017 at 7:26
  • 1
    escape the square brackets [.....]
    – Kamaraj
    Feb 15, 2017 at 7:51

1 Answer 1

7

The square brackets [ and ] are special characters in sed. You must escape them with a backslash, like so:

sed -i -e 's/\[Word1 Word2\]//g'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .