Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Foreach loop to run a perl script on multiple files Post 302341304 by greptastic on Wednesday 5th of August 2009 12:43:05 PM
Old 08-05-2009
Foreach loop to run a perl script on multiple files

Hi,

I have thousands of files in a directory that have the following 2 formats:

289620178.aln
289620179.aln
289620180.aln
289620183.aln
289620184.aln
289620185.aln
289620186.aln
289620187.aln
289620188.aln
289620189.aln
289620190.aln
289620192.aln....

and:

alnCDS_1.fasta
alnCDS_2.fasta
alnCDS_3.fasta
alnCDS_4.fasta
alnCDS_5.fasta
alnCDS_6.fasta
alnCDS_7.fasta
alnCDS_8.fasta
alnCDS_9.fasta
alnCDS_10.fasta....



I am using the following foreach statement to run a perl script like so:

foreach file1 ( *.aln ) ; foreach file2 ( *.fasta )
foreach? ./perl.script.pl $file1 $file2 > $file1$file2.out
foreach? end

This gives me output files

289620178.alnalnCDS_1.fasta.out
289620178.alnalnCDS_2.fasta.out
289620178.alnalnCDS_3.fasta.out .....

when what I want is the following:

289620178.alnalnCDS_1.fasta.out
289620179.alnalnCDS_2.fasta.out
289620180.alnalnCDS_3.fasta.out.... etc...

so that each of the files (*.aln and *.fasta) are sequentially paired as input into the perl script without all of the possible pairs being run through.

Is there a way to do this ?

Thanks!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl - Iterating a hash through a foreach loop - unexpected results

i've reworked some code from an earlier post, and it isn't working as expected i've simplified it to try and find the problem. i spent hours trying to figure out what is wrong, eventually thinking there was a bug in perl or a problem with my computer. but, i've tried it on 3 machines with the... (5 Replies)
Discussion started by: quantumechanix
5 Replies

2. Programming

PERL, search and replace inside foreach loop

Hello All, Im a Hardware engineer, I have written this script to automate my job. I got stuck in the following location. CODE: .. .. ... foreach $key(keys %arr_hash) { my ($loc,$ind,$add) = split /,/, $arr_hash{$key}; &create_verilog($key, $loc, $ind ,$add); } sub create_verilog{... (2 Replies)
Discussion started by: riyasnr007
2 Replies

3. Shell Programming and Scripting

Run perl script on files in multiple directories

Hi, I want to run a Perl script on multiple files, with same name ("Data.txt") but in different directories (eg : 2010_06_09_A/Data.txt, 2010_06_09_B/Data.txt). I know how to run this perl script on files in the same directory like: for $i in *.txt do perl myscript.pl $i > $i.new... (8 Replies)
Discussion started by: ad23
8 Replies

4. Shell Programming and Scripting

Run perl script with multiple file arguments

Hello everyone, I have two types of files in a directory: *.txt *.info I have a perl script that uses these two files as arguments, and produces a result file: perl myScript.pl abc.txt abc.xml How can I run this script (in a "for" loop , looping through both types of files)... (4 Replies)
Discussion started by: ad23
4 Replies

5. Shell Programming and Scripting

foreach loop in unix script

Hi all, I have a script which searches for all sql files in the current directory and replaces all sql files with an underscore with a dash. The next part I need to do is record the number of changes made (underscore to dash) and display this value (e.g.2). This is what I have so far; find /... (17 Replies)
Discussion started by: shawi
17 Replies

6. Shell Programming and Scripting

How to run perl script on multiple files of two directories?

Hi I have 100 files under file A labled 1.txt 2.txt.....100.txt(made up name) I have 1 files under file B labled name.txt How can i run the same perl script on 100 files and file name.txt I want to run perl script.pl A/1.txt B/name.txt perl script.pl A/2.txt B/name.txt ....... perl... (3 Replies)
Discussion started by: grace_shen
3 Replies

7. UNIX for Dummies Questions & Answers

Run one script on multiple files and print out multiple files.

How can I run the following command on multiple files and print out the corresponding multiple files. perl script.pl genome.gff 1.txt > 1.gff However, there are multiples files of 1.txt, from 1----100.txt Thank you so much. No duplicate posting! Continue here. (0 Replies)
Discussion started by: grace_shen
0 Replies

8. Shell Programming and Scripting

Run one script on multiple files and print out multiple files.

How can I Run one script on multiple files and print out multiple files. FOR EXAMPLE i want to run script.pl on 100 files named 1.txt ....100.txt under same directory and print out corresponding file 1.gff ....100.gff.THANKS (4 Replies)
Discussion started by: grace_shen
4 Replies

9. Shell Programming and Scripting

How to use a loop for multiple files in a folder to run awk command?

Dear folks I have two data set which there names are "final.map" and "1.geno" and look like this structures: final.map: gi|358485511|ref|NC_006088.3| 2044 gi|358485511|ref|NC_006088.3| 2048 gi|358485511|ref|NC_006088.3| 2187 gi|358485511|ref|NC_006088.3| 17654 ... (2 Replies)
Discussion started by: sajmar
2 Replies

10. Shell Programming and Scripting

Print perl hash value in foreach loop

Experts - Any advice on how to get a hash value in a foreach loop? Values print correctly on standalone print statements, but I can't access value in foreach loop. See sample code below and thanks in advance. foreach my $z (sort keys %hash) { for $y (@{$hash{$z}}) { print "$z... (6 Replies)
Discussion started by: timj123
6 Replies
VERSION:(1)							   User Commands						       VERSION:(1)

NAME
PyNAST - alignment of short DNA sequences SYNOPSIS
pynast [options] {-i input_fp -t template_fp} DESCRIPTION
[] indicates optional input (order unimportant) {} indicates required input (order unimportant) Example usage: pynast -i my_input.fasta -t my_template.fasta OPTIONS
--version show program's version number and exit -h, --help show this help message and exit -t TEMPLATE_FP, --template_fp=TEMPLATE_FP path to template alignment file [REQUIRED] -i INPUT_FP, --input_fp=INPUT_FP path to input fasta file [REQUIRED] -v, --verbose Print status and other information during execution [default: False] -p MIN_PCT_ID, --min_pct_id=MIN_PCT_ID minimum percent sequence identity to consider a sequence a match [default: 75.0] -l MIN_LEN, --min_len=MIN_LEN minimum sequence length to include in NAST alignment [default: 1000] -m PAIRWISE_ALIGNMENT_METHOD, --pairwise_alignment_method=PAIRWISE_ALIGNMENT_METHOD method for performing pairwise alignment [default: uclust] -a FASTA_OUT_FP, --fasta_out_fp=FASTA_OUT_FP path to store resulting alignment file [default: derived from input filepath] -g LOG_FP, --log_fp=LOG_FP path to store log file [default: derived from input filepath] -f FAILURE_FP, --failure_fp=FAILURE_FP path to store file of seqs which fail to align [default: derived from input filepath] -e MAX_E_VALUE, --max_e_value=MAX_E_VALUE Depreciated. Will be removed in PyNAST 1.2 -d BLAST_DB, --blast_db=BLAST_DB Depreciated. Will be removed in PyNAST 1.2 SEE ALSO
http://pynast.sourceforge.net Version: pynast 1.1 August 2011 VERSION:(1)
All times are GMT -4. The time now is 08:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy