I'm trying to remove the = and ] characters using one sed command:

# echo "A=[A]" | sed s'/[=\]]/ /g'

Something is wrong with this syntax?

I Expect the following results from sed

# echo "A=[A]" | ....sed 
A [A
  • 2
    Should that expected result have one space in it or two or none? Because it currently has one, and those other options require slightly different solutions.
    – Ladadadada
    Feb 21, 2013 at 10:32
  • If you want the result to replace every occurrence of "[" and "A" with a space, I'd use tr. One of those "using the wrong tool (i.e, overly complex) for the job" situations. Feb 27, 2013 at 0:59

3 Answers 3


echo "A=[A]" | sed s'/[]=]/ /g'

A [A


You can use the '-e' flag to execute multiple substitutes, for example:

# echo "A = [A]" | sed -e 's/=//' -e 's/]//'
A  [A

It might be possible to match both '=' and ']' in a single substitute but even if it is, I don't think it'll provide much benefit over using '-e'.


It's probably easier to use tr to do something like this as it doesn't involve messing with REs

echo "A=[A]<-" | tr "]=" " "
A [A <- 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.