How do I change the contents of a file from this:
setenv api1000 Delhi
setenv CODEDROP regular
setenv RELEASETYPE build
setenv CDBUILD CD30
To this (replaced string regular to CD29 in second line)
setenv api1000 Delhi
setenv CODEDROP CD29
setenv RELEASETYPE build
setenv CDBUILD CD30
my attempt:
my $CD_VER = CD29;
open RF, "<$OldFile" or die "Cannot open $OldFile for reading.";
open WF, ">$NewFile" or die "Cannot open $NewFile for writing.";
while ( <RF> ) {
if (/CODEDROP/){
if( /regular/) {
$_ =~ s/regular/$CD_VER/ ;
print WF "$_";
}
}
close RF;
close WF;
copy("$NewFile","$OldFile"); # both became same
OUTPUT I am getting as below in destination file:
setenv api1000 Delhi
setenv CODEDROP regular ( I NEED to REMOVE this LINE )
setenv CODEDROP CD29 ( only this line should be there )
setenv RELEASETYPE build
setenv CDBUILD CD30
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…