Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

escaped characters in sed

Status
Not open for further replies.

tradntele

Programmer
Nov 7, 2001
14
US
Trying to use one sed command to delete the following 3 characters "[]

Tried...

sed "s/[\"\[\]]//g" filename

It did not work, but when I just include 2 of these escaped characters in the set, it works fine. Any ideas?
 
Escaping characters inside a [] pair does not work in sed. To search for a ] you must make it the first character. The other 2 special characters are ^ which loses its special meaning it it is not first and - which loses its special meaning if it is first or last.
Code:
sed 's/[]["]//g' fn
CaKiwi
 
Have you tried doing it in a script instead? Something that you can set the variables in? ie:

blah="[]"
newblah=whatyouwantittobe
cat filename sed -e s/$blah/$whatyouwantittobe/g > newfilename

You definitely want to try this on a new or copied file as if the arguments don't match, you'll get a zero-length file.

Cheers,

Jacques
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top