0

I have a string like: b"a

and I want to replace it with string: ]b"a

The quotation mark here is very annoying, maybe some one can help me here?

2
  • 1
    Could you explain the statement The quotation mark here is very annoying? It might help us solve your problem as I suspect it probably isn't as simple as it appears to be. Commented Jul 11, 2014 at 19:27
  • I solved it. Thank u, Morton! Commented Apr 25, 2015 at 14:34

1 Answer 1

2
echo 'b"a' | sed 's|b"a|]&|'  ## & represents the matched string; 

Outputs:

]b"a
  • Use g to replace all matches in a line: sed 's|b"a|]&|g'

Similarly in Bash if you have it stored in a variable:

A='b"a'
B=${S/b\"a/]b\"a}   ## B=${S//b\"a/[b\"a} to replace all occurrences 
echo "$B"

Outputs:

]b"a
Sign up to request clarification or add additional context in comments.

2 Comments

Why echo when you can <<< ?
@Aleks-DanielJakimenko Yes you can. However the OP didn't say where he gets his string so using echo would give less explanation. We also don't know if he's really using bash despite giving the tag to it. Despite being out of scope mentioning <<< may also be instructive but still optional.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.