Skip to content

Instantly share code, notes, and snippets.

@lavoiesl
Created July 27, 2014 06:43
Show Gist options
  • Save lavoiesl/432827990d78c3764f50 to your computer and use it in GitHub Desktop.
Save lavoiesl/432827990d78c3764f50 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Convert file from iso-8859-* to UTF8 if needed
#
# @link https://gist.github.com/lavoiesl/432827990d78c3764f50
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