Lines Concatenation between two files.

Posted by Nano HE on Stack Overflow See other posts from Stack Overflow or by Nano HE
Published on 2010-04-15T13:48:41Z Indexed on 2010/04/15 14:23 UTC
Read the original article Hit count: 260

Filed under:
|
|

file1.txt

hello
tom
well

file2.txt

world
jerry
done

How to merge file1.txt with file2.txt; then create a new file - file3.txt

hello world
tom jerry
well done

thank you for reading and reply.

Attached the completed code.

#!/usr/bin/perl
use strict;
use warnings;

open(F1,"<","1.txt") or die "Cannot open file1:$!\n"; 
open(F2,"<","2.txt") or die "Cannot open file2:$!\n";
open (MYFILE, '>>3.txt');

while(<F1>){ 
  chomp; 
  chomp(my $f2=<F2>); 
  print MYFILE $_ . $f2 ."\n"; 
} 

© Stack Overflow or respective owner

Related posts about perl

Related posts about input