call this script like 
perl script.pl File_name.txt
perl script.pl < File_name.txt
more File_name.txt | perl script.pl

my $count=0;
while (<>){
   $count++ if /VIOLATE/;
}
print $count;

Must work

-----Original Message-----
From: Boon Chong Ang [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 16, 2003 10:30 AM
To: [EMAIL PROTECTED]
Subject: search and count


Hi,

I am a beginner to Perl. Well, I have a scenario like this. I have a
pattern like VIOLATE in the file. So, I want to use the perl to search
that pattern and see how many times it found such pattern. For example

 

VIOLATE

ABC

ABC

ABC

VIOLATE  ABC VIOLATE [in the same row and so I want it to count as one]

ABC

ABC

VIOLATE

VIOLATE

 

I just want to report as 4 only. 

 

 

Thank you & best regards,

ABC

 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to