输入:
orf00007 PHAGE_Prochl_MED4_213_NC_020845-gi|472340344|ref|YP_007673870.1| 7665 8618 0.210897481636936
orf00007 PHAGE_Prochl_MED4_213_NC_020845-gi|472340344|ref|YP_007673870.1| 7665 8618 0.210897481636936
orf00007 PHAGE_Prochl_P_HM2_NC_015284-gi|326783200|ref|YP_004323597.1| 7665 8618 0.207761175236097
orf00015 PHAGE_Megavi_lba_NC_020232-gi|448825467|ref|YP_007418398.1| 11594 13510 0.278721920668058
orf00015 PHAGE_Acanth_moumouvirus_NC_020104-gi|441432357|ref|YP_007354399.1| 11594 13510 0.278721920668058
我实施的脚本:
use feature qw/say/;
use Math::Trig;
open FILE,"out02.txt";
my @file=<FILE>;
close FILE;
my $aa=0;
for(my $i=$aa; $i <=17822; $i++){
if (($file[$i]>=0.210)){
open(OUTFILE,'>>OUT_t10-t10.txt');
print OUTFILE $file[$i];
}
else{}
}
注意:
输出:
orf00007 PHAGE_Prochl_MED4_213_NC_020845-gi|472340344|ref|YP_007673870.1| 7665 8618 0.210897481636936
orf00007 PHAGE_Prochl_MED4_213_NC_020845-gi|472340344|ref|YP_007673870.1| 7665 8618 0.210897481636936
orf00015 PHAGE_Megavi_lba_NC_020232-gi|448825467|ref|YP_007418398.1| 11594 13510 0.278721920668058
orf00015 PHAGE_Acanth_moumouvirus_NC_020104-gi|441432357|ref|YP_007354399.1| 11594 13510 0.278721920668058
答案 0 :(得分:0)
以下类似的脚本可能适合您:
use strict;
use warnings;
use autodie;
die "Usage: $0 number file\n"
if @ARGV != 2;
my $minval = shift;
while (<>) {
my @cols = split;
print if $col[-1] >= $minval;
}
执行它:
perl yourscript.pl 0.210 out02.txt >> OUT_t10-t10.txt
或使用perl one-liner:
perl -lane 'print if $F[-1] >= 0.210' out02.txt >> OUT_t10-t10.txt
答案 1 :(得分:0)
使用awk:
awk -v value=0.210 '$NF >= value' file
或者
awk -v value=0.210 '$NF >= value' file > output_file
答案 2 :(得分:0)
这个脚本(灵感来自你的)解决了这个问题:
use strict;
use warnings;
my $user_filter = 0.21;
open my $input_file, "<", "out02.txt" or die $!; # Modern way of open files
open my $output_file, ">>", "OUT_t10-t10.txtt" or die $!;
while( my $line=<$input_file> ) {
if( $line =~ / ([\d\.]+)\s*$/ ) {
# If a number was found at the end of line
if( $1 > $user_filter ) { # Check condition
print $output_file $line; #Write to output file
}
}
}
close $input_file;
close $output_file;