rahulruns:

If the two header lines are always the first two lines, you could just discard the first two lines, like:

my $line = <$INPUT_FH>; $line = <$INPUT_FH>; while ($line = <$INPUT_FH>) { # process file }

Of course, that'll be a problem if you ever have a file with a missing header, or if the header repeats later on in the file. in that case, you could take advantage of the fact that the lines you want to keep always start with a number:

while (my $line = <$INPUT_FH>) { # Ignore all lines not beginning with a number next unless $line =~ /^\s*\d/; # process file }

If you have other lines that you want to keep that don't start with a number, though, then you'll have to match the lines and reject them:

while (my $line = <$INPUT_FH>) { # Ignore the header lines next if $line =~ /^(procs|\s*r\s+b\s+swpd)/; # process file }

In this case, you'll need to make your pattern complete enough to recognize the header and not reject the other lines you want to keep.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Removing matched pattern except the first pattern by roboticus
in thread Removing matched pattern except the first pattern by rahulruns

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.