On Fri, 02 Nov 2007 13:03:59 -0500, Ed Morton wrote:
> On 11/2/2007 12:54 PM, Minh wrote:
>> Hi,
>>
>> How to get awk prints the last 5 lines of the file and one line before
>> last 10 lines.
>>
>>
>> Thanks
>> Minh
>>
>>
> This should be close:
>
> awk 'NR==FNR{nr++;next} (FNR==nr-11) || (FNR>(nr-5))' file file
>
> Ed.
I'm not sure, according to what I understood of the
OP request, it wouldn't be:
# awk 'NR==FNR{nr++;next} (FNR==nr-10) || (FNR>(nr-5))' file file
Anyway, just in case an "hybrid" solution is admitted:
# tac file | awk 'NR==11||NR<=5' | tac
and, if it should deal with a very big file, this would
save a lot of cycles ;-)
# tac file | awk 'NR==11||NR<=5; NR==11{exit}' | tac


|