commana (owner)

Revisions

gist: 34843 Download_button fork
public
Description:
Changes charset of files recursively
Public Clone URL: git://gist.github.com/34843.git
Embed All Files: show embed
Bash #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
 
ICONVBIN='/usr/bin/iconv' # path to iconv binary
 
ORIGINAL_IFS=$IFS
IFS=$'\n'
 
if [ $# -lt 3 ]
then
echo "$0 dir from_charset to_charset"
    exit
fi
 
find . -type f -print | while read f
do
if test -f $f
    then
files=$(echo "$f" | egrep "((\.php)|(\.html?)|(\.txt)|(\.sql)|(\.mkf)|(\.xml)|(\.css)|(\.js))$")
     if [ -n "$files" ]
     then
echo "Converting $files"
/bin/mv $f $f.old
$ICONVBIN -f $2 -t $3 $f.old > $f
rm -f $f.old
fi
else
echo "Skipping $f - not a regular file";
    fi
done
 
IFS=$ORIGINAL_IFS