Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How to add a new line after three or four lines from a pattern after getting that pattern

by jwkrahn (Abbot)
on Apr 03, 2019 at 19:23 UTC ( [id://1232111]=note: print w/replies, xml ) Need Help??


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

This appears to do what you require:

#!/usr/bin/perl use strict; use warnings; if ( @ARGV != 1 ) { print "USAGE :: perl default_operating_condition_update.pl <<FILE> +>\n\n"; exit 1; } my $inputfile = $ARGV[ 0 ]; # input FILE mkdir 'finallib' unless -d 'finallib'; open my $INFILE, '<', $inputfile or die "Can not open '$inputfile' bec +ause: $!"; open my $OPFILE, '>', "finallib/$inputfile" or die "Can not open 'fina +llib/$inputfile' because: $!"; while ( my $iline = <$INFILE> ) { print $OPFILE $iline; if ( $iline =~ /^ ( \s* ) operating_conditions \s* \( \s* ( .* ) \ +s* \) \s* { \s* $/x ) { my ( $leading_space, $operating_cond ) = ( $1, $2 ); until ( $iline =~ /^ \s* } \s* $/x ) { $iline = <$INFILE>; print $OPFILE $iline; } print $OPFILE "${leading_space}default_operating_conditions : +$operating_cond ;\n"; } }
  • Comment on Re: How to add a new line after three or four lines from a pattern after getting that pattern
  • Download Code

Replies are listed 'Best First'.
Re^2: How to add a new line after three or four lines from a pattern after getting that pattern
by anirbanphys (Beadle) on Apr 03, 2019 at 19:48 UTC
    Hello jwkrahn,

    I got all the correct answer after posting my request. Yes all the MONKS had given me the right answer, but I really like to appreciate and thank you for doing the correction of my posted code and doing the modification in the accurate way. This is going to be an example for me to write the code for this kind of situation if I face again.

    Thank you :) for this great help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1232111]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-23 23:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found