Guest User

Untitled

a guest
Oct 19th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. output=$(file --brief --mime-encoding "$1")
  4.  
  5. if echo "$output" | grep -qi "ISO-8859"; then
  6. encoding=$output
  7. # Backup input file
  8. cp $1 old_$1
  9. echo "Text file encoded in $encoding. Converting to UTF-8"
  10. # Convert to UTF-8 using iconv. It also replaces the original file with the newly
  11. # encoded one
  12. # Expected call: iconv -f iso-8859-<1..15> file.txt -t UTF-8 -o file.txt
  13. iconv -f $encoding $1 -t utf-8 -o $1
  14. else
  15. echo "Text file not encode in ISO-8859"
  16. fi
  17.  
  18. $~/Projects/scripts: ./fixEncodingForStations stations.txt
  19. ./fixEncodingForStations.sh: line 16: 13733 Bus error (core dumped) iconv -f $encoding $1 -t utf-8 -o $1
Add Comment
Please, Sign In to add comment