How can I merge two files?

前端 未结 4 766
别跟我提以往
别跟我提以往 2021-01-27 03:26

I have two files

File 1:

7118
7457
7591
7539
8001

File 2:

5003
5008
5011
5026
5028
5029
5031

Output t

4条回答
  •  心在旅途
    2021-01-27 03:51

    I'll use a perl script for that.

    #!/usr/bin/perl
    
    use strict;
    
    my @file1 = loadf("file1.txt");
    my @file2 = loadf("file2.txt");
    
    foreach my $line2 (@file2) {
        $line2 =~ s/^\s+//;
        $line2 =~ s/\s+$//;
        for (my $i = 0; $i < @file1; $i++) {
            $file1[$i] =~ s/^\s+//;
            $file1[$i] =~ s/\s+$//;
            #do the output
            print $file1[$i] . "," . $line2 . "\n";
        }
    
    }
    
    sub loadf($) {
        my @file = ( );
        open(FILE, $_[0] . "\n") or die("[-] Couldn't Open " . $_[0] . "\n");
        @file = ;
        close(FILE);
        return @file;
    }
    

提交回复
热议问题