Skip to content

Instantly share code, notes, and snippets.

@jfro
Last active December 13, 2015 23:28
Show Gist options
  • Save jfro/4991425 to your computer and use it in GitHub Desktop.
Save jfro/4991425 to your computer and use it in GitHub Desktop.
Converts all argument files to UTF-8 if they aren't already. Could be more flexible in future
#!/bin/sh
for sourceFile in $@
do
fromEncoding=`file --mime-encoding $sourceFile | awk '{print $2}'`
encodingCheck=${fromEncoding:0:6}
if [ $encodingCheck == "utf-16" ]; then
echo "Converting from $fromEncoding to utf-8"
tempFile="$sourceFile-temp"
iconv -f $fromEncoding -t utf-8 "$sourceFile" > "$tempFile"
mv "$tempFile" "$sourceFile"
else
echo "Skipping $sourceFile, already in $fromEncoding"
fi
done
@rudyrichter
Copy link

shell script? gross, ruby that shit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment