Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

matching twof files and print the output

by vis1982 (Acolyte)
on Dec 19, 2009 at 08:39 UTC ( [id://813495]=perlquestion: print w/replies, xml ) Need Help??

vis1982 has asked for the wisdom of the Perl Monks concerning the following question:

We have two files

One file

ALDH1A1

ITGA7

CHRNA1

PPP1R9A

ACTG1

SRGN

CD44

GRB7

and Second file

ALDH1A1 00001 NP_000680.2 ALDH1A1 00001 NP_000680.2 in vivo;yeast 2-hybrid 12081471,16189514

ITGA7 02761 NP_002197.1 CHRNA1 00007 NP_001034612.1 in vivo 10910772

PPP1R9A 16000 NP_060120.2 ACTG1 00017 NP_001605.1 in vitro;in vivo 9362513,12052877

SRGN 01513 NP_002718.2 CD44 00115 NP_000601.3 in vivo 9334256

GRB7 03311 NP_005301.2 ERBB2 01281 NP_004439.2 in vitro;in vivo 9079677

PAK1 03995 AAC24716.1 ERBB2 01281 NP_004439.2 in

And output shud be

ALDH1A1 NP_000680.2

ITGA7 NP_002197.1

CHRNA1 NP_001034612.1

PPP1R9A NP_060120.2

ACTG1 NP_001605.1

SRGN NP_002718.2

CD44 NP_000601.3

GRB7 NP_005301.2

#!/usr/bin/perl -w $j=1; open (FILE,"$ARGV[0]") or die; my @temp =<FILE>; close FILE; foreach $x(@temp) { chomp($x); $line = $1; $flag = 1; } open (FILE,"$ARGV[1]") or die; my @parse=<FILE>; close FILE; open(WRITE,">output.txt"); { if($flag==1){ if ($x==$parse[$0]) { print WRITE "$x $j\n $line\n";$j++;} } }

Replies are listed 'Best First'.
Re: matching twof files and print the output
by jwkrahn (Abbot) on Dec 19, 2009 at 09:15 UTC
    #!/usr/bin/perl use warnings; use strict; ( my ( $file_1, $file_2 ) = @ARGV ) == 2 or die "usage: $0 file_1 file +_2\n"; my $data = do { local $/; open my $FH, '<', $file_2 or die "Cannot open '$file_2' $!"; <$FH>; }; open my $FH, '<', $file_1 or die "Cannot open '$file_1' $!"; open my $WRITE, '>', 'output.txt' or die "Cannot open 'output.txt' $!" +; $\ = $/; while ( <$FH> ) { chomp; next unless /\S/; print $WRITE $data =~ /($_)\s+\d+(\s+\S+)/; } __END__

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://813495]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2025-02-07 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (94 votes). Check out past polls.