我确实有文字操作问题,我需要在awk,sed&外壳。
我的文字看起来像这样:
>Sample_1
100 101
aaattattacaaaaataattacaaattattacaaaaagaattattacaaaaagaattacaaaa
-1.60 .(((((((.....)))))))........................................... []
>Sample_2
1 35
aattattacaaaaagaattattacaaaaagaatta
0.00 ................................... _
>Sample_3
1 123
gctcacacctgtaatcccagcactttgggaggctgagg
-27.80 ((((.....))))......((((((.(((...))))))).)[][][[][]]
-26.40 (((((.((...(((((..((((((....))......... [[][]][]
-25.80 ((((.....)))).....((((((............... [][][][[][]]
123 145
ctgaggcaggcagatcacgaggtcacgagatcaa
-26.20 (((.....)))))) [][][[][]]
-25.90 ....((((..((....)) [][[][]]
-25.70 ..(((..((....))..(()) [[][]][[][]]
145 256
gtaatcccagcactttgggaggctgaggcaggcaga
0.00 ........................................... _
256 342
-25.00 ..((....((((.....((((((...)))....))... [[][]]
-24.00 ..((.((((.((((())... [[][][]]
-23.70 .((((((...(((((..((.. [[][]][]
我想:
>Sample_1
); -27.80;-26.40;-25.80
)提取数字开始(这是最负值)。完美的输出看起来像这样:
>Sample_1
-1.60
>Sample_2
0.00
>Sample_3
-27.80
-26.20
0.00
-25.00
我尝试在awk打印$ 1,grepping'>',0&负值,但无法将列分成几组并且并提取最负面的价值。
awk '{print $1}' file | egrep -i '>|0.00|-'
答案 0 :(得分:3)
您使用sed
和awk
标记了您的问题,但如果您是O.K.用Perl代替,你可以写:
#!/usr/bin/perl -w
use warnings;
use strict;
my $min = undef;
while(<>)
{
if(m/^(-?\d+\.\d+)/)
{
if(! defined($min) || $1 < $min)
{ $min = $1; }
}
else
{
if(defined $min)
{
print "$min\n";
$min = undef;
}
if(m/^>/)
{ print; }
}
}
if(defined $min)
{ print "$min\n"; }
答案 1 :(得分:1)
awk '/^[0-]/ && new_group {print $1} {new_group = (/^[ \t]/)} /^>/' file