批量修改文件格式

#!/bin/bash
# 2016-02-08
# check encoding and convert files
for f in `find | egrep -v Eliminate`
do
    case "$f" in
    *.c | *.cpp | *h)
    encoding=`file -bi $f | cut -f 2 -d";" | cut -f 2 -d=`
    case $encoding in
        "utf-16le" | "utf-16be")
        iconv -f $encoding -t utf-8 $f > $f.utf8
        mv $f.utf8 $f
        ;;
    esac
    ;;
    esac
done

 

 

#!/bin/bash
# 2016-02-08
# check encoding and convert files
dir=$1
echo $dir
for f in `find $dir | egrep -v Eliminate`
do
        case "$f" in
        *.c | *.cpp | *h)
        encoding=`file -bi $f | cut -f 2 -d";" | cut -f 2 -d=`
        case $encoding in
                "utf-16le" | "utf-16be")
                iconv -f $encoding -t utf-8 $f > $f.utf8
                mv $f.utf8 $f
                ;;
        esac
        ;;
        esac
done

 

你可能感兴趣的:(linux命令)