in reply to Merging of files with some edit.

Try

#!/usr/bin/perl use strict; use warnings; if (@ARGV < 2) { print "USAGE :: perl lib_marge.pl <<MAIN_LIB_FILE>> <<LIB_FILE_FOR +_MARGE>> \n\n" ; exit(1); } # read first file my $file1 = shift @ARGV; open IN,'<',$file1 or die "Can not open $file1 for input : $!"; print "$file1 opened for input\n"; my @file1 = <IN>; close IN; # remove last line pop @file1; # create new file my $outfile = 'Output.csv'; open OUT,'>',$outfile or die "Can not open $outfile for output : $!"; print "$outfile opened for output\n"; print OUT $_ for @file1; # add other files my $last; for my $infile (@ARGV){ open IN,'<',$infile or die "Can not open $infile for input : $!"; print "$infile opened for input\n"; my $flag = 0; my @lines = (); while (my $line = <IN>) { if ($line =~m/^\s*cell\s*\(\"(.*)\"\)/g || $line =~m/^\s*cell\((.*)\)/g || $line =~m/^\s*cell\s*\((.*)\)/g) { $flag = 1 } push @lines,$line if $flag; } close IN; $last = pop @lines; # remove last line print OUT $_ for @lines; } print OUT $last; # add last line close OUT;
poj

Replies are listed 'Best First'.
Re^2: Merging of files with some edit.
by anirbanphys (Beadle) on Jun 25, 2019 at 15:28 UTC
    Thank you poj. Your given code is working well. Thank you so much for the help :).

    Regards,

    Anirban