Skip to content

Instantly share code, notes, and snippets.

@cyrsap
Forked from akost/convert.sh
Created December 4, 2017 14:41
Show Gist options
  • Save cyrsap/e8f1b63dc3aaff31b30175727f415f30 to your computer and use it in GitHub Desktop.
Save cyrsap/e8f1b63dc3aaff31b30175727f415f30 to your computer and use it in GitHub Desktop.
Bash script for recursive file convertion windows-1251 --> utf-8
#!/bin/bash
# Recursive file convertion windows-1251 --> utf-8
# To add file type by extension, e.g. *.cgi, add '-o -name "*.cgi"' to the find command
find ./ -name "*.m" -o -name "*.cpp" -o -name "*.c" -o -name "*.h" -o -name "*.hpp" -type f |
while read file
do
echo " $file"
fileinfo=`file -b $file`
if [[ "$fileinfo" == *"ISO-8859"* ]] || [[ "$fileinfo" == *"1251"* ]]; then
iconv -c -f cp1251 -t UTF-8 $file -o $file.iconv.tmp
rm -f $file
mv $file.iconv.tmp $file
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment