Skip to content

Instantly share code, notes, and snippets.

@SebDeclercq
Created November 29, 2016 11:00
Show Gist options
  • Select an option

  • Save SebDeclercq/a1d393b3fc0cf5fd2b3f1941ea4ab0c1 to your computer and use it in GitHub Desktop.

Select an option

Save SebDeclercq/a1d393b3fc0cf5fd2b3f1941ea4ab0c1 to your computer and use it in GitHub Desktop.
#/usr/bin/bash
function versUtf8() {
entree=$1;
sortie=${2:-versUtf8Output.txt};
charset=$(file -i $entree |grep -oP '(?<=charset=).*');
if [ $charset == 'unknown-8bit' ]
then
charset='windows-1252'
fi
printf "ENTREE: %20s > %10s\n" $entree $charset;
iconv -f $charset $entree -t utf-16 -o versUtf8.tmp;
iconv -f utf-16le versUtf8.tmp -t utf-8 -o $sortie;
charsetSortie=$(file -i $sortie |grep -oP '(?<=charset=).*');
printf "SORTIE: %20s > %10s\n" $sortie $charsetSortie;
}
# nous@tour:~/Documents$ versUtf8 ap.csv tutututututututu.txt
# ENTREE: ap.csv > us-ascii
# SORTIE: tutututututututu.txt > utf-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment