Last active
October 21, 2015 12:18
-
-
Save dedeexe/b222b932539ea373fb0c to your computer and use it in GitHub Desktop.
Converting files to UTF-8 example
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 | |
#conversor.sh | |
#Author.....: dede.exe | |
#E-mail.....: [email protected] | |
#Description: Convert all files to a another format | |
# It's not a safe way to do it... | |
# Just a desperate script to save my life... | |
# Use it such a last resort... | |
to_format="utf8" | |
file_pattern="*.java" | |
files=`find . -name "${file_pattern}"` | |
echo "==================== CONVERTING ====================" | |
#Try convert all files in the structure | |
for file_name in ${files} | |
do | |
#Get file format | |
file_format=`file $file_name --mime-encoding | cut -d":" -f2 | sed -e 's/ //g'` | |
if [ $file_format != $to_format ]; then | |
file_tmp="${unit_file}.tmp" | |
#Rename the file to a temporary file | |
mv $file_name $file_tmp | |
#Create a new file with a new format. | |
iconv -f $file_format -t $to_format $file_tmp > $file_name | |
#Remove the temporary file | |
rm $file_tmp | |
echo "File Name...: $file_name" | |
echo "From Format.: $file_format" | |
echo "To Format...: $to_format" | |
echo "---------------------------------------------------" | |
fi | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment