J
John Smith
Hi expert,
I have the below scenario.
I have a text file called test.txt with quite a few lines. Then I need
to replace only two words("cleardiff" and "xmldiffmrg") with a common
word, "cleardiffmrg" in a few lines that start with "_xml". I need to
save the same file, test.txt after the replacement is done:
Below is the code:
------------------
open (FILE1, "C:\\test.txt") || die "Can not open the file: $!\n";
@array = <FILE1>;
close FILE1;
open (FILE2, ">C:\\test.txt") || die "Can not write to the merge file:
$!\n";
foreach (@array)
{
if (($_ =~ /^_xml\s+merge/) or ($_ =~ /^_xml\s+xmerge/))
{
s/cleardiff/cleardiffmrg/g;
s/xmldiffmrg/cleardiffmrg/g;
print FILE2;
}
}
------------------
I get only those two lines, but not the whole file with modified word,
cleardiffmrg.
What is wrong with my code?
Thanks
John
########## test.txt has the following lines########
####start of file###
_rose annotate ..\..\bin\tfdmgr.exe
_html2 xmerge ..\..\bin\htmlmgr.exe
_html2 annotate ..\..\bin\bdtm.exe
_html2 get_cont_info ..\..\bin\bdtm.exe
_xml2 construct_version ..\..\bin\bdtm.exe
_xml2 create_branch ..\..\bin\bdtm.exe
_xml2 compare ..\..\bin\cleardiff.exe
_xml2 xcompare ..\..\bin\xmldiffmrg.exe
_xml2 merge ..\..\bin\cleardiff.exe
_xml2 xmerge ..\..\bin\xmldiffmrg.exe
_xml2 annotate ..\..\bin\bdtm.exe
_xml2 get_cont_info ..\..\bin\bdtm.exe
_rose2 construct_version ..\..\bin\bdtm.exe
_rose2 create_branch ..\..\bin\bdtm.exe
### end of file ####
I have the below scenario.
I have a text file called test.txt with quite a few lines. Then I need
to replace only two words("cleardiff" and "xmldiffmrg") with a common
word, "cleardiffmrg" in a few lines that start with "_xml". I need to
save the same file, test.txt after the replacement is done:
Below is the code:
------------------
open (FILE1, "C:\\test.txt") || die "Can not open the file: $!\n";
@array = <FILE1>;
close FILE1;
open (FILE2, ">C:\\test.txt") || die "Can not write to the merge file:
$!\n";
foreach (@array)
{
if (($_ =~ /^_xml\s+merge/) or ($_ =~ /^_xml\s+xmerge/))
{
s/cleardiff/cleardiffmrg/g;
s/xmldiffmrg/cleardiffmrg/g;
print FILE2;
}
}
------------------
I get only those two lines, but not the whole file with modified word,
cleardiffmrg.
What is wrong with my code?
Thanks
John
########## test.txt has the following lines########
####start of file###
_rose annotate ..\..\bin\tfdmgr.exe
_html2 xmerge ..\..\bin\htmlmgr.exe
_html2 annotate ..\..\bin\bdtm.exe
_html2 get_cont_info ..\..\bin\bdtm.exe
_xml2 construct_version ..\..\bin\bdtm.exe
_xml2 create_branch ..\..\bin\bdtm.exe
_xml2 compare ..\..\bin\cleardiff.exe
_xml2 xcompare ..\..\bin\xmldiffmrg.exe
_xml2 merge ..\..\bin\cleardiff.exe
_xml2 xmerge ..\..\bin\xmldiffmrg.exe
_xml2 annotate ..\..\bin\bdtm.exe
_xml2 get_cont_info ..\..\bin\bdtm.exe
_rose2 construct_version ..\..\bin\bdtm.exe
_rose2 create_branch ..\..\bin\bdtm.exe
### end of file ####