兩個文件拼一個

網上的題


文件a.txt

ATCGTCGAGTCGA
GTCGTAGCT
CGATGCTAACTCAA
CGATCGATCAGCAT


文件 b.txt

23	45
34	76
34	67
37	78


請輸出文件

ATCGTCGAGTCGA	23	45
GTCGTAGCT	34	76
CGATGCTAACTCAA	34	67
CGATCGATCAGCAT	37	78

直接上代碼

#!/usr/bin/perl -w

use strict;

my (@array1,@array2);

open my $file,'<','a.txt' or die "$!\n";

while (<$file>) {
       chomp;
       next if /^$|^#/;
       push @array1,"$_\t" if $_;
}

open $file,'<','b.txt' or die "$!\n";

while (<$file>) {
       chomp;
       next if /^$|^#/;
       push @array2,"$_" if $_;
}

for my $str (@array1) {
    $str .= shift @array2;
    print $str,"\n"
}

輸出

[root@lb-01 home]# perl a.pl
ATCGTCGAGTCGA   23 45
GTCGTAGCT       34 76
CGATGCTAACTCAA  34 67
CGATCGATCAGCAT  37 78

代碼圖片

wKiom1PfPD_wZ2I1AAFulh9_G3M689.jpg

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章