Help me add [] to my SED command

I am trying to replace various punctuation with spaces using SED.

Here is my current code

sed 's/[[]-=+|~!@#\$%^&*(){}:;'\'''\"''\`''\.''\/''\\']/ /g'

I need to add [] to my command so i can replace those characters as well.
I have tried adding them as []& \[\] & '\[''\]' & "\[""\]"
But nothing seems to work.

Any help is appreciated.

echo 'a[bc];)x(d:ef&-y/z\r' | sed 's/[]=+|~!@#\$%^&*(){}:;.`"/-[]/ /g' | sed "s/'/ /g"

for this kind of thing the best tool is tr.

I tried this but whenever there is a $ in my string (e.g. word1$word2-word3) my output looks like "word1"

$ echo 'a[bc];)x(d:ef&-y/z\rword$word2-word3' | sed 's/[]=+|~!@#\$%^&*(){}:;.`"/-[]/ /g'
a bc   x d ef -y z rword word -word

Here is the final code I ended up with

sed 's/[][+|~!@#\$%^&*?,><(){}:;'\'''\"''\`''\.''\/''\\'=-]/ /g' 

I had to put = and - at the very end.

1 Like