-----Original Message-----
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, July 18, 2006 9:47 PM
To: beginners@perl.org
Subject: Re: search option in perl

Sayed, Irfan (Irfan) wrote:
 >
 >> -----Original Message-----
 >> From: Rob Dixon [mailto:[EMAIL PROTECTED]  >> Sent: Tuesday, July
18, 2006 9:09 PM  >> To: beginners@perl.org  >> Subject: Re: search
option in perl  >>  >> Sayed, Irfan (Irfan) wrote:
 >>
 >>>I need to search a file for a specific string thru perl script.
 >>>
 >>>for example i want to put following condition in the script.
 >>>
 >>>--- > first search the string string1  >>>----> and if that string
found then search for another string string2  >>>----> if both the
string found then print both the string on shell  >>>prompt  >>  >>  >>
Hi Irfan  >>  >> I think you want to search a file for all lines that
contain both string  >> 1 and string2, is that right? This does what you
want  >>  >>  > perl -n -e "print if /string1/ and /string2/" file  >>
>> But it may be that string1 and string2 can be on separate lines.
Please  >> could you calrify for us? Thanks,  >  > Hi rob,  > you are
right .
 >
 > basically I need to search two different strings in one file which
are  > at different lines.
 > means string1 is on one line and string2 is on another line  >  > can
u plz give then actual syntax to achieve this ? that will be really  >
good.

Irfan.

(Please put your responses at the bottom of the post you are replying
to)

I'm still not exactly sure, but try this. It prints all lines from the
file after 'string1' and then 'string2' is found.

   use strict;
   use warnings;

   open my $fh, 'file' or die $!;

   my ($found1, $found2);

   while (<$fh>) {
     next unless $found1 +=/string1/;
     next unless $found2 +=/string2/;
     print;
   }

I hope this helps.

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/>
<http://learn.perl.org/first-response>

  hi rob,

  Thanks for your mail.

  let me modify my request in more clear manner.
  basically I have one file. The format of that file is as follows.

  Replica name : some string
  master replica : some string
  hostname : some string

  replica name : some string
  master replica : some string
  hostname : some string
    
  so what I want is , search this entire file for following thing

  if Replica name option contains "cmvobsvr1mum" word(string) then print
both these line . I mean print
  
   replica name : some string_cmvobsvr1mum
   master replica : some string

  I need to achieve this . plz help

  regards
  irfan.

   




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to