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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |