I am trying to replace a string in a text file using Perl script. The value gets replaced successfully. However, it shifts the remaining text of the line to the next line. I want the line to be intact as before. Can someone help?
sample_file_dml
has the below text in it:
seq_no,1,1,GET,xyz
seq_no,1,2,PUT,xyz
I want to replace seq_no
in each line with the value of variable seq_no_value
. This value is obtained through some calculations in my code (for example - 9999).
Expected output:
9999,1,1,GET,xyz
9999,1,2,PUT,xyz
But, I am getting the below output:
9999
,1,1,GET,xyz
9999
,1,2,PUT,xyz
Code snippet used:
open my $IN, '<', $sample_dml_file or die $!;
open my $OUT, '>>', $new_dml_file or die $!;
while (<$IN>) {
s/(seq_no)/$seq_no_value/g;
print {$OUT} $_;
}
close $OUT or die $!;
question from:
https://stackoverflow.com/questions/65901232/replacing-some-string-in-a-text-file-shifts-the-remaining-text-to-next-line 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…