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

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

A [A

| improve this answer | |
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'.

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

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.