Link to home
Start Free TrialLog in
Avatar of faithless1
faithless1

asked on

Remove Invalid Characters

Hi,

I have a file with with bad characters which includes foreign characters which I need to remove from a file. Below is list of characters that appear in my file. I need to remove all non-standard characers. Thanks in advance

¿¿¿ ¿¿ ¿¿¿
¿¿¿¿¿ ¿¿¿¿¿
¿¿¿¿¿ ¿¿¿¿¿ ¿¿ ¿¿¿¿¿¿
¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿¿
¿¿¿¿¿ ¿¿¿¿¿¿
¿¿¿¿ ¿¿¿¿¿ ¿¿¿
¿¿¿ ¿¿¿¿¿¿¿
¿¿¿¿¿ ¿¿¿¿¿¿¿¿
¿¿¿¿¿ ¿¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿
¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿¿¿¿¿
¿¿
¿¿¿¿¿¿ ¿
¿¿¿¿¿¿ ¿ ¿
¿¿¿¿¿¿ ¿ ¿ ¿¿
¿¿¿¿¿¿ ¿ ¿¿¿¿ ¿¿¿¿¿¿¿¿¿
¿¿¿¿¿ ¿¿
¿¿¿¿¿¿ ¿¿ ¿¿¿
¿¿¿¿¿¿ ¿ ¿¿¿¿
¿¿  
¿¿    
 ¿ ¿ ¿ ¿
¿¿ ¿ ¿   ¿¿
¿¿ ¿ ¿ ¿ ¿¿¿ ¿¿¿¿ ¿¿ ¿ ¿¿ ¿¿ ¿¿
¿¿ ¿ ¿ ¿¿
¿¿ ¿ ¿ ¿¿ ¿¿¿¿¿ ¿
¿¿ ¿ ¿ ¿¿¿¿¿
¿¿ ¿ ¿ ¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿¿¿¿¿¿
¿¿ ¿ ¿ ¿¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿
¿¿ ¿ ¿  
¿¿ ¿ ¿¿ ¿
¿¿ ¿ ¿¿ ¿ ¿¿
¿¿ ¿ ¿¿ ¿ ¿¿¿
¿¿ ¿ ¿¿ ¿¿
¿¿ ¿ ¿¿ ¿¿ ¿¿
¿¿ ¿ ¿¿ ¿¿ ¿¿¿
¿¿ ¿ ¿¿ ¿¿ ¿¿¿ ¿¿
¿¿ ¿ ¿¿ ¿¿¿
¿¿ ¿ ¿¿ ¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿
¿¿ ¿ ¿¿ ¿¿¿¿
¿¿ ¿ ¿¿¿
¿¿ ¿ ¿¿¿ ¿¿
¿¿ ¿ ¿¿¿ ¿¿¿¿
¿¿ ¿ ¿¿¿ ¿¿¿¿ ¿¿ ¿¿¿¿
¿¿ ¿ ¿¿¿¿
¿¿ ¿ ¿¿¿¿ ¿¿¿ ¿¿
¿¿ ¿ ¿¿¿¿¿
¿¿ ¿ ¿¿¿¿¿ ¿¿¿
¿¿ ¿ ¿¿¿¿¿¿
¿¿ ¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿
¿¿ ¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿¿ ¿¿¿ ¿¿¿¿¿¿ ¿ ¿¿¿¿¿¿ ¿ ¿¿¿¿¿¿¿
¿¿ ¿ ¿¿¿¿¿¿¿ ¿¿¿¿¿¿¿¿
¿¿ ¿ ¿¿¿¿¿¿¿¿ ¿ ¿
¿¿¿¿¿¿ ¿¿¿¿
¿¿¿¿¿¿ ¿¿¿¿ ¿¿ ¿¿
¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿¿¿¿
¿¿¿¿¿¿ ¿¿¿¿¿
¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿
¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿
¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿
¿¿¿¿¿¿ ¿¿¿¿¿ ¿¿¿¿¿
¿¿ ¿¿
¿¿¿¿¿¿ ¿¿¿¿ ¿¿
¿¿ ¿¿ ¿
¿¿ ¿    ¿
¿¿ ¿¿   ¿ ¿
¿¿ ¿¿ ¿ ¿ ¿¿ ¿ ¿¿
¿¿ ¿¿ ¿ ¿¿
¿¿ ¿¿ ¿ ¿¿ ¿
¿¿ ¿¿ ¿ ¿¿ ¿¿
¿¿ ¿¿ ¿ ¿¿ ¿¿¿ ¿¿¿
¿¿ ¿¿ ¿ ¿¿¿¿
¿¿¿¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿
¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿
¿¿ ¿¿ ¿¿ ¿ ¿
¿¿ ¿¿ ¿¿ ¿ ¿¿
¿¿ ¿¿ ¿¿ ¿ ¿¿ ¿¿¿
¿¿ ¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿¿ ¿¿¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿ ¿¿¿¿¿
¿¿ ¿¿ ¿¿ ¿¿ ¿¿¿¿¿
¿¿ ¿¿ ¿¿ ¿¿¿
¿¿ ¿¿ ¿¿ ¿¿¿ ¿
¿¿ ¿¿ ¿¿ ¿¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿¿¿ ¿¿ ¿¿¿ ¿¿¿¿¿¿
¿¿ ¿¿ ¿¿ ¿¿¿ ¿¿¿
¿¿ ¿¿ ¿¿ ¿¿¿ ¿¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿¿¿ ¿¿¿¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿¿¿¿
¿¿ ¿¿ ¿¿ ¿¿¿¿ ¿¿ ¿¿ ¿¿¿
¿¿ ¿¿ ¿¿ ¿¿¿¿ ¿¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿¿¿
¿¿ ¿¿ ¿¿ ¿¿¿¿¿ ¿¿
¿¿ ¿¿ ¿¿ ¿¿¿¿¿¿
¿¿ ¿¿ ¿¿ ¿¿¿¿¿¿¿¿¿¿¿¿
¿¿ ¿¿ ¿¿¿
¿¿ ¿¿ ¿¿¿ ¿
¿¿ ¿¿ ¿¿¿ ¿ ¿¿
¿¿ ¿¿ ¿¿¿ ¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿¿ ¿¿
¿¿ ¿¿ ¿¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿¿ ¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿¿ ¿¿ ¿¿¿
¿¿ ¿¿ ¿¿¿ ¿¿ ¿¿¿¿
¿¿ ¿¿ ¿¿¿ ¿¿¿
¿¿ ¿¿ ¿¿¿ ¿¿¿ ¿¿
¿¿ ¿¿ ¿¿¿ ¿¿¿ ¿¿¿¿ ¿¿¿
¿¿ ¿¿ ¿¿¿ ¿¿¿¿
¿¿ ¿¿ ¿¿¿ ¿¿¿¿¿
¿¿ ¿¿ ¿¿¿¿
¿¿ ¿¿ ¿¿¿¿ ¿¿
¿¿ ¿¿ ¿¿¿¿ ¿¿ ¿¿¿
¿¿ ¿¿ ¿¿¿¿ ¿¿¿
¿¿ ¿¿ ¿¿¿¿ ¿¿¿ ¿¿ ¿¿¿
¿¿ ¿¿ ¿¿¿¿ ¿¿¿ ¿¿¿ ¿¿¿
¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿ ¿¿
¿¿ ¿¿ ¿¿¿¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿ ¿¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿ ¿¿¿ ¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿ ¿¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿ ¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿ ¿¿ ¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿¿ ¿¿¿ ¿¿ ¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿
¿¿ ¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿¿¿¿¿
¿¿ ¿¿ ¿¿¿¿¿¿
¿¿ ¿¿ ¿¿¿¿¿¿¿
¿¿ ¿¿ ¿¿¿¿¿¿¿¿¿¿
¿¿¿¿¿¿ ¿¿¿¿¿¿¿
¿¿ ¿¿¿
¿¿ ¿¿¿ ¿
¿¿ ¿¿¿ ¿ ¿¿
Avatar of faithless1
faithless1

ASKER

File with special characters included
file.txt
I suspect it would be easier to search for all allowable characters.  Do all allowable characters make up a simple set?  Such as ascii, latin-1, etc.?

What encoding have you used for the text file you supplied?
You can process each character using the script below

for line in $(cat file.txt)
do
      lln=`expr length $line`
      for ((c=1; c<=$lln; c++))
      do
            chrr= $(echo $line | cut -c$c)
            echo "${chrr}"
      done
done

now at echo "${chrr}" you can replace it with the some character identified mechanism. I believe you can check every character if it falls in some allowable range then use it else discard the character.

something like below
if [ $chrr -gt 31 -a $chrr -lt 125 ]


ASKER CERTIFIED SOLUTION
Avatar of Dushyant Sharma
Dushyant Sharma
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial