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' Commented Feb 15, 2017 at 7:26
  • 1
    escape the square brackets [.....] Commented 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.