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.