nitrobass24 nitrobass24 - 1 year ago 113
Bash Question

How do i replace [] brackets using SED

I have a string that i am want to remove punctuation from.

I started with

sed 's/[[:punct:]]/ /g'

But i had problems on HP-UX not liking that all the time, and some times i would get a 0 and anything after a
in my string would dissappear. So i decided to try to do it manually.

I have the following code which works on all my punctuation that I am interested in, except I cannot seem to add square brackets "[]" to my sed with anything else, otherwise it does not replace anything, and i dont get an error, so I am not sure what to fix.

Anyways this is what i currently have and would like to add

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

BTW I am using KSH on Solaris, Redhat & HP

Answer Source

Here is the final code I ended up with

`echo "$string" | sed 's/[^a-zA-Z0-9]/ /g'`

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download