Guest User

Convert UTF8-to-ASCII-to-UTF8

a guest
Feb 1st, 2015
1,316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. #!/bin/sh
  2. ## Convert strange characters to known ones.
  3.  
  4. #set -x
  5.  
  6. if [ $# -ne 2 ]
  7. then
  8.     echo "Usage: $0 src_file dst_file"
  9.     exit 1
  10. fi
  11.  
  12. find_chars=("é" "É" "è" "ê" "ë" "ô" "à" "â" "ç" "Ç" "ù" "û" "î" "ï")
  13. rplc_chars=("é"  "É"  "è"  "ê"  "ë"  "ô"  "à"  "â"  "ç"  "Ç"  "ù"  "û"  "î"  "ï")
  14.  
  15. num_chars=${#find_chars[@]}
  16.  
  17. if [ $num_chars -ne ${#rplc_chars[@]} ]
  18. then
  19.     echo "There must be as many items in both arrays"
  20.     exit 1
  21. fi
  22.  
  23. cp $1 $2
  24.  
  25. for (( i=0; i<= $((num_chars - 1)); i++ ))
  26. do
  27.     find_chr="${find_chars[$i]}"
  28.     rplc_chr="${rplc_chars[$i]}"
  29.     echo "Replacing ${find_chr} to ${rplc_chr}..."
  30.     sed -i "s/${find_chr}/${rplc_chr}/g" $2
  31. done
Advertisement
Add Comment
Please, Sign In to add comment