A
A
Arteben2014-08-13 12:33:48
Perl
Arteben, 2014-08-13 12:33:48

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

1 answer(s)
K
Konkase, 2014-08-13
@Arteben

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 your question

Ask a Question

731 491 924 answers to any question