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
精彩评论