使用DOS文件内容作为BASH中的命令行参数

时间:2009-11-20 21:21:30

标签: bash scripting

这是此问题answer的后续行动。

如何修改代码,以便在传递给xargs之前可以删除DOS创建文件的烦人CRLF?

示例文件'arglist.dos'。

# cat > arglist.unix
src/file1 dst/file1
src/file2 dst/file2
src/file3 dst/file3
^c
# sed 's/$/\r/' arglist.unix > arglist.dos

该文件的unix变体适用于此:

$ xargs -n2 < arglist.unix echo cp
cp src/file1 dst/file1
cp src/file2 dst/file2
cp src/file3 dst/file3

对于我自己的教育,如何更改它以接受同一命令行中的'arglist.unix'或'arglist.dos'文件?

2 个答案:

答案 0 :(得分:1)

在将文件传递给xargs之前,使用d2u删除CR。

答案 1 :(得分:1)

cat arglist.dos | tr -d "\r" | xargs -n2 echo cp

给你的结果与

相同
cat arglist.unix | tr -d "\r" | xargs -n2 echo cp

所以它适用于这两个文件。

tr -d "\r"删除所有CR字符