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/


Relevant Pages

  • Re: [PHP] can button onclick executed a bash script
    ... > of javascript but can it do the same with bash script ... and then depending on the button clicked can execute ... scalable system for accessing system services | ...
    (php.general)
  • Re: BASH vulnerability
    ... The patch for Linux issued today didn't fix it completely, ... execute the following: ... the vulnerability has to do with any bash script ...
    (comp.sys.mac.system)
  • Re: BASH vulnerability
    ... The patch for Linux issued today didn't fix it completely, ... execute the following: ... the vulnerability has to do with any bash script ...
    (comp.sys.mac.system)
  • Re: php shell-script
    ... Safran von Twesla wrote: ... > I'm trying to execute a working php-script within a bash script which ... > is itself started by cron. ... > It doesn't seem to work.Everything in the bash script is executed ...
    (alt.os.linux)
  • Re: Switching users in a bash script?
    ... How can I most easily accomplish this task? ... my question was whether I can 'su' in a bash script so that the commands that follow the 'su' in che script will be executed as the su'ed user. ... You will have to type each user's password unless the main script runs as root, or unless you use sudo (using "nopasswd" in the sudoers file so user a can execute command b as user c). ...
    (comp.os.linux.misc)