If you want to exclude certain blocks you need to keep track where you are in the file
use Modern::Perl; # this is the list of sections to change my @sections = qw/ messages secure cron maillog /; # we put it in a hash for easy lookup my %sections = map { $_ => 1 } @sections; # Herein we remember where we are my $section; while ( my $line = <DATA> ) { # Remember the current section $section = $1 if ( $line =~ m| \[ monitor:// (?: / ( [^/]+ ) )+ \] |x ); # Change the index line if the current section # is one that interests us $line =~ s/ index = ([A-Z0-9]+) _ (np|pr) /** index=LINUX_${2} +/x #<-- you can remove the indent here once you see it works if defined $sections{ $section }; print $line; } __DATA__ [monitor:///var/log/cron] index=NDNW_np sourcetype=syslog [monitor:///var/log/maillog] index=BSKX_np sourcetype=syslog [monitor:///var/log/secure] index=NDNDK_np sourcetype=syslog [monitor:///var/log/spooler] index=DNWN_np sourcetype=syslog [monitor:///var/log/audit/audit.log] index=XBJB_np sourcetype=syslog [monitor:///var/log/messages] index=JNJSJ_pr sourcetype=syslog [monitor:///var/log/cron] index=NCJG_pr sourcetype=syslog [monitor:///var/log/maillog] index=JE3K_pr sourcetype=syslog [monitor:///var/log/secure] index=NLNDKN_pr sourcetype=syslog [monitor:///var/log/spooler] index=EKJC_pr sourcetype=syslog [monitor:///var/log/audit/audit.log] index=QKNK_pr sourcetype=syslog


holli

You can lead your users to water, but alas, you cannot drown them.

In reply to Re: How do i use perl for replacing capture group content by holli
in thread How do i use perl for replacing capture group content by Zagidi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.