Created
December 10, 2010 12:50
-
-
Save arthurfurlan/736166 to your computer and use it in GitHub Desktop.
Convert files from some encoding to another using the "iconv". edit
This file contains hidden or 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/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