Skip to content

Instantly share code, notes, and snippets.

@arthurfurlan
Created December 10, 2010 12:50
Show Gist options
  • Select an option

  • Save arthurfurlan/736166 to your computer and use it in GitHub Desktop.

Select an option

Save arthurfurlan/736166 to your computer and use it in GitHub Desktop.
Convert files from some encoding to another using the "iconv". edit
#!/bin/sh
# written by Arthur Furlan <[email protected]>
# check the script usage
if [ $# -lt 1 ]; then
echo "Usage: $0 PATH [FROM-ENCODING] [TO-ENCODING]"
exit 1
elif [ ! -d $1 ]; then
echo "Error: directory $1 not found."
exit 2
fi
# define the encodings to be used, default: iso -> utf
F_ENC=${2:-'iso-8859-1'}
T_ENC=${3:-'utf-8'}
# convert the files
find $1 -type f | while read FNAME; do
NEW_FNAME="/tmp/$(basename $FNAME)"
iconv -f $F_ENC -t $T_ENC -o $NEW_FNAME $FNAME
mv $NEW_FNAME $FNAME
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment