Skip to content

Instantly share code, notes, and snippets.

@lavoiesl
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save lavoiesl/11052359 to your computer and use it in GitHub Desktop.

Select an option

Save lavoiesl/11052359 to your computer and use it in GitHub Desktop.
convert a file to UTF-8 using iconv
#!/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