从概念上讲,我想实现这样的目标:
sed 's|<pattern>|<replace>|' <filename> --> cp <sedoutput> <somewhere>
一般情况下: 我想将每行从sed逐个传递到另一个不接受管道的命令,所以xargs可能不适用。也许有时我甚至想在第二个命令的参数列表中放入多个位置。有可能吗?
答案 0 :(得分:2)
您可以使用command substitution
:
cp "$(sed 's|<pattern>|<replace>|' filename)" somewhere
如果sed正在产生多行输出,那么使用process substitution
:
while read -r f; do
cp "$f" somewhere
done < <(sed 's|<pattern>|<replace>|' filename)
答案 1 :(得分:2)
sed 's|<pattern>|<replace>|' filename | while read EachOccurrence
do
cp "${EachOccurrence}" "${somewhere}"
done
读取需要可能-r
输入行中出现\
答案 2 :(得分:1)
只需使用xargs
sed 's|<pattern>|<replace>|' file | xargs -i{} cp {} somewhere