in reply to Substitute in a subparagraph

As soon as you get into nesting, you really need a parser. Fortunately, some properties of your data language allow us to construct one rather easily.

use strict; use warnings; sub process_para { my ($para) = @_; if (my ($id) = $para =~ /^(\w+)/) { if ($id ne 'blabla5') { $para =~ s/^TEXT TO BE REMOVED\n//mg; } } print($para); } { my ($depth, $buf); while (<DATA>) { $buf .= $_; ++$depth if /\(\s*$/; --$depth if /^\s*\)\s*$/; #printf("[%d] %s", $depth, $_); if (!$depth) { process_para($buf); $buf = ''; } } die("Bad nesting\n") if $depth; } __DATA__
blabla_data[28] OUTPUT ( REQUIRED ( lead_up 0.193118 br fclk clkdom(3) early_lea clkdom(3) late_trail_dn -0.084738 br fclk clkdom(3) late_tra ) cext %0.00151055 min_ceff_up %0.034 TEXT TO BE REMOVED ) blabla5 [145] OUTPUT ( REQUIRED ( early qclk clkdom(6) early_l qclk clkdom(7) late_trail_dn -0.125163 bf qclk clkdom(7) late_t(7) TEXT TO BE REMOVED ) )

Update: With the new data format, you'll need

sub process_para { my ($para) = @_; if (my ($id) = $para =~ /^ [ ]* (\S+)/x) { if ($id !~ /^.*clk\[\d\]\z/) { $para =~ s/^ [ ]* QUALIFIED [ ]* \n//xmg; } } print($para); }

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.