Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
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 '13 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. – Belmin Fernandez Feb 27 '13 at 0:59
up vote 4 down vote accepted

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

A [A

share|improve this answer

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'.

share|improve this answer

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 <- 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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