Просто отбрасывайте вывод первой итерации.
top -bn2 | awk '/^top -/ { p=!p } { if (!p) print }'
ну я держу пари, что это не самый элегантный код, и он может быть также сокращен, но это для вашей домашней работы: -)
w |awk '{
if (NR!=1){
if($5 ~ /days/){
split($5,d,"days");
print $1,d[1]*5184000" sec"
}
else if( $5 ~ /:|s/){
if ($5 ~/s/) { sub(/s/,"",$5); split($5,s,"."); print $1,s[1]" sec" }
else if ( $5 ~/m/) { split($5,m,":"); print $1,(m[1]*60+m[2])*60" sec" }
else { split($5,m,":"); print $1,m[1]*60+m[2]" sec" }
}
else { print $1,$5}
}}'
-121--84556- Я знаю, что это не совсем то, что вы после, но лично - я не уживаюсь с неловко
и поэтому предложил бы идти в порядке.
Что-то вроде этого:
#!/usr/bin/perl
#REALLY GOOD IDEA at the start of any perl code
use strict;
use warnings;
#open some files for input
open( my $exons, "<", 'exons.bed' ) or die $!;
#record where our exons start and finish.
my %start_of;
my %end_of;
#read line by line our exons file.
#extract the 3 fields and save 'start' and 'end' in a hash table.
while (<$exons>) {
my ( $something, $start, $end ) = split;
my $exon_id = $.; #line number;
$start_of{$exon_id} = $start;
$end_of{$exon_id} = $end;
}
close ( $exons );
my %exons;
#run through 'reads' line by line, extracting the files.
open( my $reads, "<", 'reads.bed' ) or die $!;
while (<$reads>) {
my ( $thing, $read_start, $read_end, $value ) = split;
#cycle through each exon.
foreach my $exon_id ( keys %start_of ) {
#check if _this_ 'read' is within the start and end ranges.
if ( $read_start >= $start_of{$exon_id}
and $read_end <= $end_of{$exon_id} )
{
#store the line number in our hash %exons.
push( @{ $exons{$exon_id} }, $. );
}
}
}
close ( $reads );
#cycle through %exons - in 'id' order.
foreach my $exon_id ( sort keys %exons ) {
#print any matches.
print "exon ",$exon_id, " (", $start_of{$exon_id}, " - ", $end_of{$exon_id},
") contains reads of line:", join( ",", @{ $exons{$exon_id} } ), "\n";
}
Что дает ваш образец данных:
exon 1 (60005 - 60100) contains reads of line:1
exon 2 (61007 - 61130) contains reads of line:2,3,4,5
Вы должны иметь возможность расширить это, чтобы сделать некоторые более сложные проверки диапазона/валидации тривиально!
-121--86023-Существуют инструменты, которые сначала отображают вычисленное среднее значение. Другие инструменты имеют неполный первый образец. В целом рекомендуется пропустить первый образец, чтобы получить желаемый результат.