Advertisement
iarmin

iso2utf8

May 1st, 2011
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.72 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. #: Filename    : iso2utf8
  4. #: Title       : iso2utf8 - ISO-8859-2 to UTF-8 converter
  5. #: Author      : "Iarmin" <[email protected]>
  6. #: Version     : 0.9
  7. #: Description : Converts files from iso-8859-2 to utf-8. Skips already converted files. Creating backup.
  8. #: Dependency  : iconv, isutf8[moreutils]
  9. #: Options     : ./iso2utf8 <file1> <file2> <file3> ...
  10. #
  11.  
  12.  
  13. for f in "$@"; do
  14.     bakf="${f}.bak"
  15.  
  16.     if [ ! -f "$f" ]; then
  17.         echo "$f: cannot open"
  18.     fi
  19.  
  20.     if isutf8 "$f" &> /dev/null; then
  21.         echo "$f: already in UTF-8"
  22.     else
  23.         mv "$f" "$bakf"
  24.        
  25.         iconv -f iso-8859-2 -t utf-8 "$bakf" > "$f"
  26.    
  27.         if cmp "$f" "$bakf" &> /dev/null; then
  28.             rm -f "$bakf"
  29.         else
  30.             echo "$f: converted"
  31.         fi
  32.     fi
  33. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement