Last active
August 29, 2015 14:00
-
-
Save lavoiesl/11052359 to your computer and use it in GitHub Desktop.
convert a file to UTF-8 using iconv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Convert file from iso-8859-* to UTF8 if needed | |
| if [[ $# -lt 1 ]]; then | |
| echo "Usage: $0 input-file" >&2 | |
| exit 1 | |
| fi | |
| mime_encoding="$(file -b --mime-encoding "$1")" | |
| if [[ "$mime_encoding" == iso-8859-* ]]; then | |
| tmp=$(mktemp -t iconv-utf8) | |
| iconv -f $"mime_encoding" -t UTF-8 "$1" > "$tmp" | |
| mv "$tmp" "$1" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment