Hello Eshan_k,

Here’s a straightforward approach using two variables to keep track of which plane and filter type we are “in” at any given input line:

use strict; use warnings; my $prefix = qr/ ^ \s* \w{3} > \s+ /x; my ($plane, $filter); while (my $line = <DATA>) { if ($line =~ / $prefix LR_PLANE_(\w+), /x) { $plane = $1; $filter = undef; print "\n$line"; } elsif ($plane) { if ($line =~ / $prefix LR_FILTER_TYPE: \s+ RESTORE_(\w+) /x) { $filter = $1; print $line; } elsif ($filter && $line =~ / $prefix $filter _ [VH] FILTER_ \d +: /x) { print $line; } } } __DATA__ ABC> LR_PLANE_Y, LRU_SIZE: 128X128, LRU_X: 0, LRU_Y: 0, ABC> Dif: 744374271, Rng: 51464, Cnt: 4, Ret: 1 ABC> LR_FILTER_TYPE: RESTORE_WIENER ABC> Literal: 0 ABC> Literal: 11 ABC> Literal: 14 ABC> Literal: 0 ABC> Literal: 12 ABC> Literal: 3 ABC> WIENER_VFILTER_0: 5, WIENER_VFILTER_1: -19, WIENER_VFILTER_2: +30 ABC> WIENER_HFILTER_0: 5, WIENER_HFILTER_1: -20, WIENER_HFILTER_2: +9 ABC> LR_PLANE_U, LRU_SIZE: 128X128, LRU_X: 0, LRU_Y: 0, ABC> Dif: 525860863, Rng: 38897, Cnt: 0, Ret: 1 ABC> LR_FILTER_TYPE: RESTORE_WIENER ABC> Literal: 2 ABC> Literal: 6 ABC> Literal: 9 ABC> Literal: 7 ABC> WIENER_VFILTER_0: 0, WIENER_VFILTER_1: -2, WIENER_VFILTER_2: 2 +2 ABC> WIENER_HFILTER_0: 0, WIENER_HFILTER_1: 2, WIENER_HFILTER_2: 11 ABC> LR_PLANE_V, LRU_SIZE: 128X128, LRU_X: 0, LRU_Y: 0, ABC> Dif: 66698751, Rng: 59048, Cnt: 9, Ret: 1 ABC> LR_FILTER_TYPE: RESTORE_WIENER ABC> Literal: 14 ABC> Literal: 4 ABC> Literal: 3 ABC> Literal: 5 ABC> WIENER_VFILTER_0: 0, WIENER_VFILTER_1: -22, WIENER_VFILTER_2: +25 ABC> WIENER_HFILTER_0: 0, WIENER_HFILTER_1: -13, WIENER_HFILTER_2: +12

Output:

13:37 >perl 1886_SoPW.pl ABC> LR_PLANE_Y, LRU_SIZE: 128X128, LRU_X: 0, LRU_Y: 0, ABC> LR_FILTER_TYPE: RESTORE_WIENER ABC> WIENER_VFILTER_0: 5, WIENER_VFILTER_1: -19, WIENER_VFILTER_2: +30 ABC> WIENER_HFILTER_0: 5, WIENER_HFILTER_1: -20, WIENER_HFILTER_2: +9 ABC> LR_PLANE_U, LRU_SIZE: 128X128, LRU_X: 0, LRU_Y: 0, ABC> LR_FILTER_TYPE: RESTORE_WIENER ABC> WIENER_VFILTER_0: 0, WIENER_VFILTER_1: -2, WIENER_VFILTER_2: 2 +2 ABC> WIENER_HFILTER_0: 0, WIENER_HFILTER_1: 2, WIENER_HFILTER_2: 11 ABC> LR_PLANE_V, LRU_SIZE: 128X128, LRU_X: 0, LRU_Y: 0, ABC> LR_FILTER_TYPE: RESTORE_WIENER ABC> WIENER_VFILTER_0: 0, WIENER_VFILTER_1: -22, WIENER_VFILTER_2: +25 ABC> WIENER_HFILTER_0: 0, WIENER_HFILTER_1: -13, WIENER_HFILTER_2: +12 13:37 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Print specific data based on regex search in previous line by Athanasius
in thread Print specific data based on regex search in previous line by Eshan_k

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.