perl编程:如果第一行第一列相同,打印第一行,第二行,第三行,第四行
各位大侠,如果第一行第一列相同,打印第一行,第二行,第三行,第四行。01.txt>SR1.2>SR1.302.txt>SR1.1HWI-STATGCTGCTTCGTCGA...
各位大侠,
如果第一行第一列相同,打印第一行,第二行,第三行,第四行。
01.txt
>SR1.2
>SR1.3
02.txt
>SR1.1 HWI-ST
ATGCTGCT
TCGTCGAT
CTGATCAGCTAC
>SR1.2 HWI-ST0
TTTTGCTGCT
TCGTTGGG
CTTTATCAGCTAC
>SR1.3 HWI-ST0787
GGGGGCTGCT
AATCGTCGAT
AACTGATCAGCTAC
result:
>SR1.2 HWI-ST0
TTTTGCTGCT
TCGTTGGG
CTTTATCAGCTAC
>SR1.3 HWI-ST0787
GGGGGCTGCT
AATCGTCGAT
AACTGATCAGCTAC
What's wrong with me?
open(IN1,"01.txt")
|| die "Cannot open this file";
@lines1 = <IN1>;
open(IN2,"02.txt")
|| die "Cannot open this file";
@lines2 = <IN2>;
open(OUT,">out01")
|| die "Cannot open this file";
for $item1(@lines1){
chomp $item1;
#print OUT $item1,"\t";
@tmp1=split(/\s+/,
$item1);
for $item2(@lines2){
chomp $item2;
@tmp2=split(/\s+/,
$item2);
if ($tmp1[0] eq
$tmp2[0]){
print OUT
$lines2[$i],"\n",$lines2[$i+1],$lines2[$i+2],$lines2[$i+3];
last;
}
$i++
}
print OUT "\n";
}
close(IN1);
close(IN2);
close(OUT);
先谢谢了! 展开
如果第一行第一列相同,打印第一行,第二行,第三行,第四行。
01.txt
>SR1.2
>SR1.3
02.txt
>SR1.1 HWI-ST
ATGCTGCT
TCGTCGAT
CTGATCAGCTAC
>SR1.2 HWI-ST0
TTTTGCTGCT
TCGTTGGG
CTTTATCAGCTAC
>SR1.3 HWI-ST0787
GGGGGCTGCT
AATCGTCGAT
AACTGATCAGCTAC
result:
>SR1.2 HWI-ST0
TTTTGCTGCT
TCGTTGGG
CTTTATCAGCTAC
>SR1.3 HWI-ST0787
GGGGGCTGCT
AATCGTCGAT
AACTGATCAGCTAC
What's wrong with me?
open(IN1,"01.txt")
|| die "Cannot open this file";
@lines1 = <IN1>;
open(IN2,"02.txt")
|| die "Cannot open this file";
@lines2 = <IN2>;
open(OUT,">out01")
|| die "Cannot open this file";
for $item1(@lines1){
chomp $item1;
#print OUT $item1,"\t";
@tmp1=split(/\s+/,
$item1);
for $item2(@lines2){
chomp $item2;
@tmp2=split(/\s+/,
$item2);
if ($tmp1[0] eq
$tmp2[0]){
print OUT
$lines2[$i],"\n",$lines2[$i+1],$lines2[$i+2],$lines2[$i+3];
last;
}
$i++
}
print OUT "\n";
}
close(IN1);
close(IN2);
close(OUT);
先谢谢了! 展开
展开全部
实践证明可以运行!
#!/usr/bin/perl
use warnings;
use strict;
use IO::File;
my $file_1 = "./wenti/data1.txt";
my $file_2 = "./wenti/data2.txt";
sub main(){
my $fh_1 = IO::File->new($file_1) or die $!;
my $fh_2 = IO::File->new($file_2) or die $!;
while(<$fh_1>){
chomp();
my $num = $_;
my $fh_2 = IO::File->new($file_2) or die $!;
while(<$fh_2>){
chomp();
my @date = split / /,$_;
my $wdate = $date[0];
if($num eq $wdate){
print $_,"\n";
}
}
}
}
&main;
#!/usr/bin/perl
use warnings;
use strict;
use IO::File;
my $file_1 = "./wenti/data1.txt";
my $file_2 = "./wenti/data2.txt";
sub main(){
my $fh_1 = IO::File->new($file_1) or die $!;
my $fh_2 = IO::File->new($file_2) or die $!;
while(<$fh_1>){
chomp();
my $num = $_;
my $fh_2 = IO::File->new($file_2) or die $!;
while(<$fh_2>){
chomp();
my @date = split / /,$_;
my $wdate = $date[0];
if($num eq $wdate){
print $_,"\n";
}
}
}
}
&main;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询