Shell脚本把文件从GBK转为UTF-8编码
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 fielif [ -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 donefi |
Shell脚本把文件从GBK转为UTF-8编码的更多相关文章
- shell脚本中文件测试
shell脚本中文件测试 author:headsen chen 2017-10-17 14:35:19 个人原创,转载请注明作者,否则 依法追究法律责任 [ -f filename ] ...
- Shell脚本统计文件行数
Shell脚本统计文件行数 转自 http://www.jb51.net/article/61943.htm 示例:row_count.sh文件 awk '{print NR}' row_cou ...
- (转)shell脚本之文件测试操作符及整数比较符
shell脚本之文件测试操作符及整数比较符 原文:http://www.cnblogs.com/Steward-Xu/p/6722592.html 一.文件测试操作符: 在书写测试表达式是,可以使用一 ...
- shell 脚本大文件处理
shell 脚本大文件处理 字符串处理 s='{"_id":{"$oid":"59b73d80930c17474f9f050d"},&qu ...
- shell脚本实现文件的自动上传以及下载 scp sftp lftp 还有expect命令
转至: 最近需求要求定期从一个[定期更新的文件] 中解析员工信息 ,插入到数据库中. 按理来说很简单, 无非就是io流读文件,然后crud balalalala..... 其实不是的, 我我写的这个 ...
- 利用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可 ...
- Shell脚本实现文件遍历和删除操作
本文需要实现的功能如下:某文件夹下具有由按数字编号命名的文件夹,需要删除除最大编码外的文件. 具体实现 大致思路:循环遍历该文件夹下所有文件,正则匹配出最大编码文件:然后循环文件,删除除最大编码外的文 ...
- shell脚本学习-文件包含
跟着RUNOOB网站的教程学习的笔记 和其他语言一样,shell也可以包含外部脚本.这样可以很方便的封装一些公用的代码作为一个独立的文件.shell文件包含的语法有两种形式 . filename # ...
- shell脚本复制文件夹内容到另外的文件夹,如果存在则自动备份
有时我们需要将一个文件夹覆盖到我们的工作目录,但需要自动备份已经存在的文件,一个一个去备份太麻烦了,全部备份又没有必要.shell脚本可以很好滴完成这个任务.原文链接http://back.zhizh ...
随机推荐
- codeforces 705B:Spider Man
Description Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a ...
- Python之异常总结
一.异常错误 a.语法错误 错误一: if 错误二: def text: pass 错误三: print(sjds b.逻辑错误 #用户输入不完整(比如输入为空)或者输入非法(输入不是数字) num= ...
- 智课雅思词汇---十八、前缀peri是什么意思
智课雅思词汇---十八.前缀peri是什么意思 一.总结 一句话总结:前缀:peri- 表示“周围, 靠近” 词根:-peri- [词根含义]:试验,尝试 [词根来源]:英语experience, e ...
- java:内存处理ByteArrayOutputStream,ByteArrayInputStream
//用内存,将小写字母替换成大写字母 String str = "helloworld,goodmorning"; ByteArrayOutputStream bos = null ...
- MVC 成功创建了数据库,但是数据库对象创建失败[此引用关系将导致不允许的周期性引用]
model 类的属性写错了 错误写法: public province { public int provinceId; public string Name; } public City ...
- 《Advanced Bash-scripting Guide》学习(三):自删除脚本和自读取内容的脚本
本文所选的例子来自于<Advanced Bash-scripting Gudie>一书,译者 杨春敏 黄毅 自删除脚本 #!/bin/rm #自删除脚本 #当你运行这个脚本时,基本上什么都 ...
- 如何理解python中的if __name__=='main'的作用
一. 一个浅显易懂的比喻 我们在学习python编程时,不可避免的会遇到if __name__=='main'这样的语句,它到底有什么作用呢? <如何简单地理解Python中的if __name ...
- cocos2d-js 创建帧动画
封装创建方法 var RunActionHelper = function(){ };RunActionHelper.prototype.createAnimationByPlist = functi ...
- python 换行
python3 end = “”:输入参数不换行. 就是打印之后不换行. python字符串换行: (1)三个单引号,例如print '''我是程序员 刚学习python''' (2)三个双引号,例如 ...
- LeetCode OJ:Same Tree(相同的树)
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...