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 ;
}
}