Categories
How to write multiline text to a file using perl script?
There is a text file in which it is necessary to write the text (multiline) after a certain line.
Answer the question
In order to leave comments, you need to log in
As an option:
#!/usr/bin/perl $string="string"; open($fh, "data1.txt"); open($fh2,"data2.txt"); while ($row = <$fh>) { chomp $row; if ($row =~ /$string/ ) { print $string."\n"; while ($row2 = <$fh2>) { chomp $row2; print $row2."\n"; } } else { print $row."\n";} }
Didn't find what you were looking for?
Ask a Question
731 491 924 answers to any question