Created
August 25, 2015 00:16
-
-
Save nbrew/eaab85dc1d05e9aca6a8 to your computer and use it in GitHub Desktop.
Use `recode` to re-encode text files to CP1252
This file contains 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 | |
# cd DEEPLINK-* | |
# find . -d -name DATA -exec recodetowin {} \; | |
function recodeifneeded(){ | |
# Find the current encoding of the file | |
encoding=$(file -I "$1" | sed "s/.*charset=\(.*\)$/\1/") | |
if [ "binary" == "${encoding}" ]; then | |
echo " Skipping -- Reported Binary File: $1" | |
du -h $1 | |
return | |
fi | |
if [ "us-ascii" != "${encoding}" ]; then | |
if [ "unknown-8bit" == "${encoding}" ]; then | |
encoding="mac" | |
fi | |
# if [ ! "$1" == "${encoding}" ]; then | |
# Encodings differ, we have to encode | |
echo "recoding from ${encoding} to CP1252 file : $1" | |
recode ${encoding}..CP1252 $1 | |
fi | |
} | |
if [ -d "${1}" ]; then | |
for f in `ls ${1}`; do | |
recodeifneeded ${1}/${f} | |
done | |
else | |
recodeifneeded ${1} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment