日期:2014-05-16  浏览次数:20621 次

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.