Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Due to some encoding problems, some characters in my database have been interpreted uncorrectly. Some chars have been replaced with the 'replacement character'. I need to find all such chars and replace them with space. I have been googling different solutions using sed, bash, perl, etc with no luck. Could someone share a solution how to find such characters (i.e. looking for this character in hex/octal value) and replace them with any other character?

Thanks.

share|improve this question
3  
bash is so the wrong tool for this. –  Ignacio Vazquez-Abrams Feb 2 '12 at 10:51
2  
Might just possibly be useful if you mentioned some tiny details like what database you're using... –  Chopper3 Feb 2 '12 at 13:33
1  
Is your database a file? Can you give an example how you see such replacement characters? –  olibre Feb 2 '12 at 17:35
3  
The Unicode "Replacement Character" glyph is usually not what is in the underlying data storage system: It's normally subbed in at the display layer (because of a decoding failure), and doesn't actually tell you what the underlying code was/is. You need to know that (and what DB you're talking about) in order to go about cleaning things up... –  voretaq7 Feb 2 '12 at 17:58
    
Thank you all for the help and replies. –  Andrew Feb 2 '12 at 20:40

1 Answer 1

up vote 6 down vote accepted

The Unicode "Replacement Character" glyph is usually not what is in the underlying data storage system: It's normally subbed in at the display layer (because of a decoding failure), and doesn't actually tell you what the underlying code was/is.

You have two options here:

The first (and best) is to find out what the underlying glyph/code is and use your database tools in order to cleanin things up.

The second is to export your data through something that does the Unicode conversions, search/replace the "Replacement Character" code there, and re-import your data. This is generally infeasible for all but the smallest data sets (and if the problem is that your workstation can't figure out what to do with the Unicode glyphs it won't fix your problem).

share|improve this answer
    
Thank you for such a comprehensive answer. You are right, I have dumped my database and found number of different strange characters in my dump. The database seems to have been affected by malicious code. I would not figure out this without your help. –  Andrew Feb 2 '12 at 20:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.