Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. #!/bin/bash
  2.  
  3. # usage: 1251toutf8.sh filename
  4.  
  5. # make the conversion
  6. iconv -f cp1251 -t utf8 $1 >/tmp/111.111
  7. if [ $? -ne 0 ]
  8. then
  9.         echo Error converting $1!
  10.         exit 1
  11. fi
  12.  
  13. # reverse conversion
  14. iconv -f utf8 -t cp1251 /tmp/111.111 >/tmp/222.222
  15. if [ $? -ne 0 ]
  16. then
  17.         echo Error back-converting $1!
  18.         exit 1
  19. fi
  20.  
  21. # compare reverse converted file with the original
  22. diff $1 /tmp/222.222
  23. if [ $? -ne 0 ]
  24. then
  25.         echo Error comparing $1!
  26.         exit 1
  27. fi
  28.  
  29. # comparison ok, replace the file
  30. cp /tmp/111.111 $1
  31.  
  32. # remove temporary files
  33. rm -f /tmp/111.111
  34. rm -f /tmp/222.222
  35.  
  36. exit 0
  37.  
  38.