Re: Executing code for files in multiple directories

From: Edward wijaya (ewijaya_at_singnet.com.sg)
Date: 07/21/04


Date: Wed, 21 Jul 2004 12:18:59 +0800

Thanks so much Foo..
Works perfectly...with such a simple way.

On Tue, 20 Jul 2004 21:18:14 GMT, foo <foo@bar.baz> wrote:

> Edward WIJAYA wrote:
>
>> Hi,
>>
>> I have a perl code, with usage:
>>
>> mycode.pl file1.fa > file1.out
>>
>> Now I would like to execute this code
>> for files in multiple directories (e.g. dir1, dir2, dir3, ...dir10).
>>
>>
>> I have already have a bash script that attempt to do it
>> but I didn't know how to proceed:
>>
>> -------------------------------
>> #!bin/bash
>>
>> for i in *
>> do
>> if [ -d $i ]
>> then
>> find $i -name '*.fa*'
>>
>> #perl mycode.pl $i > #????? don't know how to go from here
>> fi
>> done
>> -------------------------------------
>>
>> Would any body kindly advice
>> how can I go from there?
>>
>> Thanks so much for your time.
>> Hope to hear from you again.
>>
>> Regards,
>> Edward WIJAYA
>> SINGAPORE
>
> Note that BASH scripts cannot handle new-line characters in the file
> name.
> If your *.fa* files contain new-line characters in their name, consider
> using: "find ... -print0 | xargs -0 perl ..."; otherwise the code below
> will work just fine.
>
> The loop in your script can be simplified to the following:
>
> find dir1 dir2 ... dir10 -name '*.fa*' -print | \
> while read -r i
> do
> perl mycode.pl "$i" > "$i.out"
> done
>
> You might also try <http://freshmeat.net/projects/ff/> if you find
> yourself
> having to write such "file loop" BASH scripts on a regular basis:
>
> ff -rme '*.fa*' 'perl mycode.pl "$f" > "$f.out"' dir1 dir2 ...
> dir10
>
>

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/