in reply to Re^4: Counting matches
in thread Counting matches
How big are the 2 files ? Try
poj#!/usr/bin/env perl use strict; use warnings; my %count = (); my $dir = '/home/nic/Desktop/5-27-17/'; my $file1 = $dir.'Genomes_used_hant.txt'; open IN,'<',$file1 or die "Could not open $file1 : $!"; while (<IN>){ chomp; $count{$_} = 0; } close IN; my $file2 = $dir.'NRT2.txt'; my $n = 0; open IN,'<',$file2 or die "Could not open $file2 : $!"; while (my $line = <IN>){ if ($line =~ /^>(.*)_/){ ++$count{$1} if exists $count{$1}; } ++$n; } close IN; print "$n lines read from $file2\n\n"; for (sort keys %count){ if ($count{$_} > 0 ) { printf "%-15s count %d\n",$_,$count{$_}; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Counting matches
by Nicpetbio23! (Acolyte) on May 29, 2017 at 17:47 UTC | |
|
Re^6: Counting matches
by Nicpetbio23! (Acolyte) on May 29, 2017 at 18:20 UTC | |
by poj (Abbot) on May 29, 2017 at 18:49 UTC |