Front page | perl.beginners |
Postings from March 2008
grep usage
Thread Next
From:
Johnson, Reginald
Date:
March 26, 2008 13:08
Subject:
grep usage
I am trying to grep an array return the lines that match. From my
reading I see that grep returns the number of times an expression was
true not the actual expression. My question is how would I get the
actual expression.
I tested my code with a small input file of 2 records. The first one is
in the @mhsarray the second one is not.
I am trying to get my output file to have "CISCSTT6....line from
@mhsarray that it matched".
$ cat mhs.pl
#!/usr/bin/perl
use warnings;
$file="/adsm/nodes";
$mhs="/adsm/mhs_alloc";
$file_out="/adsm/in_mhs";
open (INFILE, "<", "$file") or
die "$file could not be opened: $!";
open (MHSFILE, "<", "$mhs") or
die "$mhs could not be opened: $!";
open (OUTFILE, ">", "$file_out") or
die "$file_out could not be opened: $!";
while (<MHSFILE>) {
chomp($_);
push (@mhsArray, $_);
}
foreach $line (<INFILE>) {
chomp($line);
print "this is line $line\n";
@inmhs = grep(/$line/,@mhsArray);
print "size of inmhs array is $#inmhs\n";
if ($#inmhs > -1) {
print (OUTFILE "$line\n"); # would like to be
$line...line from @mhsArray
# print "$_\n";
}
} #end foreach
close(INFILE);
close(MHSFILE);
close(OUTFILE);
cicstt6 () [ /a
Reggie Johnson
TSM Admin
904.218.4620
Jacksonville, Fl
--------------------------------------------------------
This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing.
--------------------------------------------------------
Thread Next
-
grep usage
by Johnson, Reginald