开发者

xargs into different files

开发者 https://www.devze.com 2023-02-03 08:11 出处:网络
I have a bash \'for loop\' that does what I want for i in *.data do ./prog $i >dir/$i.bck done Can I turn this into an xargs construct ?

I have a bash 'for loop' that does what I want

for i in *.data
do
    ./prog $i >dir/$i.bck
done

Can I turn this into an xargs construct ? I've tried something like

ls *.data|xargs -n1  -I FILE ./prog FILE >dir/FILE.bck

开发者_开发技巧But I have problems with the FILE rightside of '>'

thanks


Give this a try (you can use FILE instead of % if you prefer):

find -maxdepth 1 -name '*.data' -print0 | xargs -0 -n1 -I % sh -c './prog % > dir/%.bck'


GNU Parallel http://www.gnu.org/software/parallel/ is designed for this kind of tasks:

ls *.data | parallel ./prog {} '>'dir/{}.bck

IMHO this is more readable than the xargs solution provided.

Watch the intro video to learn more: http://www.youtube.com/watch?v=OpaiGYxkSuQ

0

精彩评论

暂无评论...
验证码 换一张
取 消