The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Tar-ing the correct directories new2ss UNIX for Dummies Questions & Answers 1 11-08-2007 10:15 PM
Correct the error plz Mandab Shell Programming and Scripting 2 05-11-2007 02:15 PM
plz correct this wannalearn Shell Programming and Scripting 8 04-26-2007 08:56 AM
to get the correct value with unsigned int naan High Level Programming 2 04-11-2007 07:29 AM
How to count the record count in an EBCDIC file. oracle8 UNIX for Dummies Questions & Answers 1 07-26-2006 08:22 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-22-2008
popeye popeye is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 25
Count not correct

the count is off ... man ... help please.

The Code


Code:
open (FILE1, "xy1.TXT") or die "$0: Could not open SOURCEFILE.TXT: $!\n";
open (FILE2, "xy2.TXT") or die "$0: Could not open RESULTFILE.TXT: $!\n";

chomp(my @strings = <FILE2>);
while (1) {
 foreach $pattern (<FILE1>) {
  chomp($pattern);
 last if $pattern =~ /^\s*$/;
  my @matches = eval {
    grep /$pattern/, @strings;
  };
  if ($@) {
    print "Error: $@";
  } else {
    my $count = @matches;
    print "$count lines in the result file contain:  $pattern \n"
  }
}
exit;
}

///////////////////////////////////////////
the files

Code:
C:\perl>type cv1.txt
car
boat
house
girl
hate


Code:
C:\perl>type cv2.txt
boy
car
girl
dog
car
love
hate
boat
boat
hate
boat
boat
boy
girl
dog


///////////////////////////////////////////
The output


Code:
C:\perl>grepc.pl
0 lines in the result file contain:  car
4 lines in the result file contain:  boat
0 lines in the result file contain:  house
2 lines in the result file contain:  girl
2 lines in the result file contain:  hate


Last edited by Yogesh Sawant; 04-22-2008 at 02:28 AM.. Reason: added code tags
 

Bookmarks

Tags
perl, regex

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0