2013-10-26 47 views

回答

2

這應該爲你工作:

awk '/^abcd/{p++;if(p==1) print}/^DDD/{q++;if(q==8||q==9)print}' file 
+1

完美。謝謝。 – chimoshoto

1
perl -lne 'push @{ $h->{$1} }, $_ if /.*(abcd|DDD).*/;END{print join "\n", @{ $h->{abcd}}[0]; print join "\n", @{ $h->{DDD}}[7..8];}' file 

或分解:

perl -lne ' 
    push @{ $h->{$1} }, $_ if /.*(abcd|DDD).*/; 
    END{ 
     print join "\n", @{ $h->{abcd} }[0], @{ $h->{DDD} }[7..8]; 
    } 
' file 
相關問題