6

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

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

Something is wrong with this syntax?

I Expect the following results from sed

# echo "A=[A]" | ....sed A [A 
2
  • 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. Commented 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. Commented Feb 27, 2013 at 0:59

3 Answers 3

6

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

A [A

9

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

5

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

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.