假设我有一个类似于此内容的脚本
/path/to/file1 /path/to/file2 /path/to/file3
/path/to/file4 /path/to/file5 /path/to/file6
/path/to/file91 /path/to/file23
/path/to/file130 /path/to/file34 /path/to/file/69 /path/to/file42
我怎样才能占用每一行,并说,例如,对所有运行rm
但是第一个文件?
答案 0 :(得分:2)
怎么样
your_script | sed 1d | xargs rm
这应该有效,因为rm需要多个args, 所以这就是将要执行的内容:
# excluded by sed: /path/to/file1 /path/to/file2 /path/to/file3
rm /path/to/file4 /path/to/file5 /path/to/file6 \
/path/to/file91 /path/to/file23 \
/path/to/file130 /path/to/file34 /path/to/file/69 /path/to/file42
如果您希望单独执行每个单词:
for f in `your_script | sed 1d`; do rm $f; done
正如斯迈勒指出的那样,也是通过以下方式实现的:
your_script | sed 1d | xargs -n 1 rm
答案 1 :(得分:1)
script | while read first rest; do
echo rm $rest
done
请确保$rest
不加引号,以便进行分词。
答案 2 :(得分:0)
多种方式:
your_script | tail -n +2 | xargs rm #Delete first line from stdout, run rm on other lines
your_script | { read x; xargs rm ; } #Read first line, ignore it. Run rm on others.
your_script | { read x; while read x; do rm $x; done ; } #Read first line, ignore it. Run rm on others, line by line. (slower...)
答案 3 :(得分:0)
your_script|perl -F -ane 'shift @F if($.==1);print "@F"'|xargs rm -rf