Home > Software engineering >  How to use Grep to replace square bracket with parenthesis
How to use Grep to replace square bracket with parenthesis

Time:05-22

I've tried but it gives me back an error message.

sed -i ‘s/[]/()/'

sed -i ‘s/\[]\/\()\/'

All helps are appreciated, thank you!

CodePudding user response:

You can try using

sed -i  'y/[]/()/'

y/source/dest/

Transliterate the characters in the pattern space which appear in source to the corresponding character in dest. (taken from manual for the command)

CodePudding user response:

Suggesting a working solution:

$ echo "text[ text ] text []" | sed '{s/\[/(/g;s/\]/)/g}'
text( text ) text ()
  • Related