http://www.jb51.net/article/51308.htm

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh 
  
## 
## convert file from GB2312 to UTF-8
## 
  
path="$1"
unset opt
if [ "$2" = "force" ]; then
    opt="-c -s"
fi
  
if [ -z "$path" ]; then
    echo "nUsage: $0 <file or dir>n"
elif [ ! -e "$path" ] ; then
    echo "nERROR: destination: $path does not exist.n"
fi
  
if [ -f "$path" ] ; then
    echo "Converting $path (gbk --> utf-8) ... "
    if file "$path"|grep -q UTF-8 >/dev/null ; then
        echo "Already converted"
    else
        iconv -f gbk $opt -t utf-8 "$path" > /tmp/$$.tmp
        if [ $? -eq 0 ] ; then
            echo "Success"
            mv -f /tmp/$$.tmp "$path"
        else
            echo "Failed"
        fi
    fi
elif [ -d "$path" ] ; then
    path=`echo "$path/"|sed 's//////'`
    find "$path" -path "$path.*" -prune -o -type f -print|while read i
    do
        dir=`dirname $i`
        file=`basename $i`
        echo "Converting $dir/$file (gbk --> utf-8) ..."
        iconv -f gbk -t utf-8 $opt "$i" > /tmp/$$.tmp 2>/dev/null
        if [ $? -eq 0 ] ; then
            echo "Success"
            mv -f /tmp/$$.tmp "$i"
        else
            echo "Failed"
        fi
    done
fi

Shell脚本把文件从GBK转为UTF-8编码的更多相关文章

  1. shell脚本中文件测试

    shell脚本中文件测试 author:headsen chen  2017-10-17  14:35:19 个人原创,转载请注明作者,否则 依法追究法律责任 [ -f  filename  ]   ...

  2. Shell脚本统计文件行数

    Shell脚本统计文件行数 转自 http://www.jb51.net/article/61943.htm    示例:row_count.sh文件 awk '{print NR}' row_cou ...

  3. (转)shell脚本之文件测试操作符及整数比较符

    shell脚本之文件测试操作符及整数比较符 原文:http://www.cnblogs.com/Steward-Xu/p/6722592.html 一.文件测试操作符: 在书写测试表达式是,可以使用一 ...

  4. shell 脚本大文件处理

    shell  脚本大文件处理 字符串处理 s='{"_id":{"$oid":"59b73d80930c17474f9f050d"},&qu ...

  5. shell脚本实现文件的自动上传以及下载 scp sftp lftp 还有expect命令

    转至: 最近需求要求定期从一个[定期更新的文件] 中解析员工信息 ,插入到数据库中. 按理来说很简单,  无非就是io流读文件,然后crud balalalala..... 其实不是的, 我我写的这个 ...

  6. 利用shell脚本统计文件中出现次数最多的IP

    比如有如下文件test.txt 1  134.102.173.43 2  134.102.173.43 3  134.102.171.42 4  134.102.170.9 要统计出现次数最多的IP可 ...

  7. Shell脚本实现文件遍历和删除操作

    本文需要实现的功能如下:某文件夹下具有由按数字编号命名的文件夹,需要删除除最大编码外的文件. 具体实现 大致思路:循环遍历该文件夹下所有文件,正则匹配出最大编码文件:然后循环文件,删除除最大编码外的文 ...

  8. shell脚本学习-文件包含

    跟着RUNOOB网站的教程学习的笔记 和其他语言一样,shell也可以包含外部脚本.这样可以很方便的封装一些公用的代码作为一个独立的文件.shell文件包含的语法有两种形式 . filename  # ...

  9. shell脚本复制文件夹内容到另外的文件夹,如果存在则自动备份

    有时我们需要将一个文件夹覆盖到我们的工作目录,但需要自动备份已经存在的文件,一个一个去备份太麻烦了,全部备份又没有必要.shell脚本可以很好滴完成这个任务.原文链接http://back.zhizh ...

随机推荐

  1. 防域名DNS劫持 从保护帐号安全做起

    什么攻击能造成区域性的网络瘫痪?没错,DNS劫持.这个堪称核武器的攻击方式,一旦爆炸,后果不堪设想.2014年1月21日,全国大范围出现DNS故障,下午,中国顶级域名根服务器出现故障,大部分网站受影响 ...

  2. 在移动端做查看日志信息的js

    Vconsole.js下载这个js引入需要使用的html文件,当运行到页面是就会在右下角显示提示,点击就出出现像pc端上的控制台页面 在线查看的网址 http://console.hongliang. ...

  3. QT 实现按住鼠标左键点击对话框空白处,拖动对话框

    定义头文件 QPoint move_point; //移动的距离     bool mouse_press; //按下鼠标左键 protected:     void mousePressEvent( ...

  4. nova cell配置

    Configuration option = Default value Description [cells] call_timeout = 60 (IntOpt) Seconds to wait ...

  5. GridRegionAdapter(slivelight)

    原地址:http://www.xuebuyuan.com/68722.html Prism学习之SilverlightWindowRegionAdapter[0评] 文章作者: healer 文章分类 ...

  6. LeetCode OJ:Sum Root to Leaf Numbers(根到叶节点数字之和)

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  7. LeetCode OJ:Same Tree(相同的树)

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  8. CentOS 6.8安装Docker V1.0

    rpm -Uvh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum -y install do ...

  9. 使用BackgroundWorker组件

    BackgroundWorker 组件用来执行诸如数据库事务.文件下载等耗时的异步操作. 开始 在应用程序中添加一个BackgroundWorker实例,如果用的是VS,可以从工具上直接拖到应用程序: ...

  10. python主函数

    Python的人会很不习惯Python没有main主函数. 这里简单的介绍一下,在Python中使用main函数的方法 #hello.py def foo(): str="function& ...