Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Converting files to UTF-8 example
#!/bin/bash
#conversor.sh
#Author.....: dede.exe
#E-mail.....: dede.exe@gmail.com
#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