Skip to content

Instantly share code, notes, and snippets.

@venj
Created September 28, 2011 03:10
Show Gist options
  • Save venj/1246893 to your computer and use it in GitHub Desktop.
Save venj/1246893 to your computer and use it in GitHub Desktop.
a simple bash wrap for iconv.
#!/bin/bash
usage() {
echo Usage: `basename $0` from_encoding to_encoding file_or_dir_to_transcode
}
if [ $# -ne 3 ]; then
usage
exit 1
fi
from=$1
to=$2
target=$3
if [ -d $target ]; then
wd=`pwd`
cd "$target"
for file in `ls -1`; do
filename=${file%.*}
iconv -f $from -t $to ${filename}.txt > ${filename}_${to}.txt
rm ${filename}.txt
done
cd "$wd"
elif [ -f $target ]; then
filename=${target%.*}
iconv -f $from -t $to ${filename}.txt > ${filename}_${to}.txt
#rm $target # Comment out this to keep original file
else
usage
exit 0
fi
unset from to target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment