freekngeek has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I am working on a script. I need to search for specific string and add two lines below that string. Like this :
I am using this code just to test my script :This is my file lvtnfet cmos20lpm lvtnfet_b symbol d g s b PROPMAP m=m And this would be my output file lvtnfet_float cmos20lpm lvtnfet_b symbol d g s b PROPMA +P m=m lvtnfet_auxpc2 cmos20lpm lvtnfet_b symbol d g s b PROPM +AP m=m
I am getting so many errors like these#!/tool/pandora/.package/perl-5.12.1/libexec/perl5.12.1 -w use strict; use warnings; my $file="device.map"; open (FH, "< $file") || die "Could not open file: $!\n"; my @lines = <FH>; close(FH); open (FH, "> $file"); for (@lines){ if ($_=~m/lvtnfet cmos20lpm lvtnfet_b symbol d g s b PR +OPMAP m=m/) print FH "lvtnfet_float cmos20lpm lvtnfet_b symbol d g +s b PROPMAP m=m \n"; print FH "lvtnfet_auxpc2 cmos20lpm lvtnfet_b symbol d g +s b PROPMAP m=m \n"; } print FH close FH; print "done\n";
I hope if someone could help me with that. Thanks.Bareword found where operator expected at device.map line 4, near "// +GLOBALFOUNDRIES" (Missing operator before GLOBALFOUNDRIES?) Bareword found where operator expected at device.map line 6, near "// +except" (Missing operator before except?) Bareword found where operator expected at device.map line 47, near "m= +m AREA=area" Bareword found where operator expected at device.map line 48, near "m= +m AREA=area"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Search and add lines into a file. Getting bareword error.
by hdb (Monsignor) on Apr 19, 2013 at 08:05 UTC | |
Re: Search and add lines into a file. Getting bareword error.
by 2teez (Vicar) on Apr 19, 2013 at 08:41 UTC | |
Re: Search and add lines into a file. Getting bareword error.
by bimleshsharma (Beadle) on Apr 19, 2013 at 10:33 UTC |
Back to
Seekers of Perl Wisdom