Skip to content

Instantly share code, notes, and snippets.

@DonRichards
Forked from lavoiesl/convert-to-utf8.sh
Created January 18, 2017 12:11
Show Gist options
  • Select an option

  • Save DonRichards/bca60e1511971bfd34e8b0f7e20615ca to your computer and use it in GitHub Desktop.

Select an option

Save DonRichards/bca60e1511971bfd34e8b0f7e20615ca 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