读书人

xargs下令得到管道中的数据

发布时间: 2013-10-27 15:21:50 作者: rapoo

xargs命令得到管道中的数据
尝试使用下面代码将所有.c文件从gbk转换为utf-8


find . -name '*.c' | xargs iconv -f gbk -t utf-8

其中iconv的格式是

iconv -f gbk -t utf-8 test.c -o test.c

现在在上面xargs脚本当中要传入两个test.c,如何实现?
[解决办法]
你这同一个文件同时作为输入和输出,会有丢失数据的风险吧。
[解决办法]
引用:
那改文件编码应该如何去改呢

find . -name '*.c' 
[解决办法]
xargs -i iconv -f UTF-8 -t Unicode {} -o {}.new

[解决办法]
楼主的意思是转换每一个文件的编码吗?

find . -name '*.c' -exec iconv -f gbk -t utf-8 {} -o {}.new \; -exec /bin/mv {}.new {} \;

[解决办法]
--replace[=replace-str], -I replace-str, -i[replace-str]
Replace occurences of replace-str in the initial arguments with names read from standard input. Also, unquoted blanks do not terminate arguments.
If replace-str is omitted, it defaults to "{}" (like for ‘find -exec’). Implies -x and -L 1.

读书人网 >UNIXLINUX

热点推荐