I'm having some mental trouble today and can't think of what to do. I have a file of data that has entry such as:

name, description, ID

I have another file with multiple groupings like the one shown above. What I'm wanting to do is count the number times the ID from the first file occurs in the second file and then group them by the ID. I would like the output to look something like

name, description, ID, # of occurrences

Below is what I've tried so far, which very obviously doesn't work. I am just simply not able to think today. If anyone can help, I'd very much appreciate it.

#! /usr/local/bin/perl -w open (CYT, "C:/Work/ING_Occurrences_Companies/CytokineArrays.txt"); while (<CYT>){ chomp; @cytokine=split(/\t/,$_);} close CYT; open (OUT, ">C:/Work/ING_Occurrences_Companies/ING_Count.txt"); open (IN, "C:/Work/ING_Occurrences_Companies/ING.txt"); while (<IN>){ chomp; @ING=split(/\t/,$_); $count = 0; if($ING[2] =~ /@cytokine[1]/){ $count++; print OUT "$ING[0]\t$ING[1]\t$cytokine{$ING[2]}\t$count\t\n"; }} close IN; close OUT;

In reply to Count Matches in a File by de2425

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.