[SWLUG] grep question

Lord, David - CSG David.Lord at hayscsg.com
Tue Feb 12 12:21:42 UTC 2002


I'd go with perl on this one...

#!/usr/local/bin/perl -w

open(EFILE, "<" . shift);

while(<EFILE>) {
  chomp;
  push( @expressions, $_ );
}

close EFILE;

open(IFILE, "<" . shift);

$lineno = 0;
while(<IFILE>) {
  for $expr ( @expressions ) {
    if( /$expr/ ) {
      print "$lineno [$expr]: $_";
      last;
    }
  }
  $lineno++;
}

close IFILE;


> -----Original Message-----
> From: bascule [mailto:excession at bigfoot.com]
> Sent: 08 February 2002 22:23
> Subject: [SWLUG] grep question
> 
> if i am feeding a file to grep that has an expression on each 
> line to search 
> through another file for matches, is there a way to output 
> the line of the 
> file that has the matching expression as well as the match, 
> or to specify 
> which line of the file to use as an expression?
 


**********************************************************************
This message (including any attachments) is confidential and may be 
legally privileged.  If you are not the intended recipient, you should 
not disclose, copy or use any part of it - please delete all copies 
immediately and notify the Hays Group Email Helpdesk at
email.helpdesk at hays.plc.uk
Any information, statements or opinions contained in this message
(including any attachments) are given by the author.  They are not 
given on behalf of Hays unless subsequently confirmed by an individual
other than the author who is duly authorised to represent Hays.
 
A member of the Hays plc group of companies.
Hays plc is registered in England and Wales number 2150950.
Registered Office Hays House Millmead Guildford Surrey GU2 4HJ.
**********************************************************************





More information about the Swlug mailing list