Hello Monks,

My intention is to print a new line "default_operating_conditions : " in a new file. The given code is able to search a pattern "operating_conditions" from the input file (INPUT) and doing some intended operation. The output of the file should be looking like file OUTPUT.

Here my code is printing the intended line just after the matched pattern in the output. I need to print the intended line after four line (5TH LINE) from the pattern.

Can you folks please guide me :).

The perl code is

use strict; use warnings; my $inputfile = $ARGV[0]; # input FILE my $opt_cond; my $iline; if ($#ARGV!=0){ print "USAGE :: perl default_operating_condition_update.pl <<FILE>> + \n\n" ; exit(1); } my $cmd = "mkdir finallib;"; system ($cmd); my @operating_cond; open (INFILE,"<","$inputfile") || die "Can not open Input LIB File"; open (my $OPFILE,">","finallib/$inputfile") || die "Can not open Input + Text File"; while ($iline = <INFILE>) { chomp $iline; print $OPFILE "$iline\n"; if ($iline =~m/^\s*operating_conditions/g) { @operating_cond=split (operating_conditions,$iline); @operating_cond=split ("{",$operating_cond[1]); @operating_cond=split (/\(/,$operating_cond[0]); @operating_cond=split (/\)/,$operating_cond[1]); $opt_cond = $operating_cond[0]; print $OPFILE " default_operating_conditions : $operating_cond[0] +;\n" ; } }

The input file for the code is

library(and_gate) { delay_model : table_lookup ; date : "Fri Mar 15 03:44:39 " ; time_unit : 1ms ; voltage_unit : 1V ; current_unit : 1A ; operating_conditions ("AB0.5v45c") { process : 1 ; temperature : 45 ; voltage : 0.5 ; } input_voltage(default) { vi : 0 ; vh : 0.5 ; vim : 0 ; vin : 0.5 ; } }

The output should be look like

library(and_gate) { delay_model : table_lookup ; date : "Fri Mar 15 03:44:39 " ; time_unit : 1ms ; voltage_unit : 1V ; current_unit : 1A ; operating_conditions ("AB0.5v45c") { process : 1 ; temperature : 45 ; voltage : 0.5 ; } default_operating_conditions : "AB0.5v45c" ; input_voltage(default) { vi : 0 ; vh : 0.5 ; vim : 0 ; vin : 0.5 ; } }

In reply to How to add a new line after three or four lines from a pattern after getting that pattern by anirbanphys

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.