monkeyking
monkeyking

Reputation: 6958

xargs into different files

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

Upvotes: 1

Views: 113

Answers (2)

Ole Tange
Ole Tange

Reputation: 2025

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

Upvotes: 0

Dennis Williamson
Dennis Williamson

Reputation: 360325

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'

Upvotes: 3

Related Questions