my-scripts/utf8.sh

32 lines
1.1 KiB
Bash
Executable file
Raw Blame History

#!/bin/bash
# Script wich converts a file in 'text/plain' from an not utf8 char set to utf8 char set
#
# (c) by Ulf Bartholom<6F>s ulfbart@gmx.de
VERSION="$0 Version 0.1.0 from 20.09.2006"
#
if [ "$1" == "" ]; then
echo "Please enter Filename as first option which should be converted"
echo
echo -e "INFO:\n\tTo convert all old latin1 file-names in new utf8 file-names use:"
echo -e "\t\t'convmv --notest -r -f latin1 -t utf-8 *'\n"
exit -1
fi
myNEWNAME=$1
myNEWNAMEsik=$(echo ${myNEWNAME}~)
myFILETYPE=$(file -bi ${myNEWNAME} | cut -d';' -f1)
myCHARSET=$(file -bi ${myNEWNAME} | cut -d'=' -f2)
# if Filetype is convertable
if [ "${myFILETYPE}" == "text/plain" ] && [ "${myCHARSET}" != "utf8" ]; then
# If sik file exists break with error message
test -e ${myNEWNAMEsik} && echo "File <${myNEWNAMEsik}> exists" && exit -2
mv ${myNEWNAME} ${myNEWNAMEsik}
# Convert the old CharSet in utf8
echo "Convert ${myNEWNAME} from ${myCHARSET} to utf8"
iconv -f ${myCHARSET} -t utf8 -o ${myNEWNAME} ${myNEWNAMEsik}
else
# Print error Message
echo "Filetype not 'text/plain' (${myFILETYPE}) or char set is 'utf8' (${myCHARSET})"
fi