![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|