BASH | detect text files charset and convert to …

MOD_INTRO_FILE_CHARSET="$(file -bi "$MOD_INTRO_FILE" | grep charset | sed "s|.*\=||" | awk '{print $1}')"
if [ "x$MOD_INTRO_FILE_CHARSET" != "x" ]; then
	    $(which iconv) -l | grep -wi $MOD_INTRO_FILE_CHARSET > /dev/null
	    if [ $? -eq 0 ]; then
		MOD_INTRO="$(cat "$MOD_INTRO_FILE" | $(which iconv) -cs -f $MOD_INTRO_FILE_CHARSET -t $CHARSET_TEXTFILE)"
	    else
		MOD_INTRO="$(cat "$MOD_INTRO_FILE")"
	    fi
	else
	    MOD_INTRO="$(cat "$MOD_INTRO_FILE")"
fi

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.