Created
September 28, 2011 03:10
-
-
Save venj/1246893 to your computer and use it in GitHub Desktop.
a simple bash wrap for iconv.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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