Hi Irfan

[...]
>   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

Not clear if you mean a string or a word, but here is one way to do it:

Dani


#!/usr/bin/perl
use strict;
use warnings;

# if the regex matches, print the actual line ($_) and the
# following line (scalar <DATA>). Repeat for every input
# line (while (<DATA>)).
# Omit the two \b if "cmvobsvr1mum" may be part of a string

/^Replica name : .*?\bcmvobsvr1mum\b.*?/
   &&
     print $_, scalar <DATA>
       while (<DATA>);

__DATA__
Replica name : some cmvobsvr1mum string
master replica : some string (1)
hostname : some string

Replica name : some string  DON'T PRINT THIS LINE
master replica : some string (2)
hostname : some string

Replica name : some string cmvobsvr1mum
master replica : some string (3)
hostname : some string

Replica name : cmvobsvr1mumsome string  DON'T PRINT THIS LINE
master replica : some string (4)
hostname : some string

-- 
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