Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Print last ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 9 Topic 2057 of 2371
Post > Topic >>

Re: Print last 5 lines

by loki harfagr <loki@[EMAIL PROTECTED] > Nov 5, 2007 at 06:29 PM

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
 




 9 Posts in Topic:
Print last 5 lines
Minh <minhcao123@[EMAI  2007-11-02 10:54:19 
Re: Print last 5 lines
Ed Morton <morton@[EMA  2007-11-02 13:03:59 
Re: Print last 5 lines
loki harfagr <loki@[EM  2007-11-05 18:29:45 
Re: Print last 5 lines
Tiago Peczenyj <tiago.  2007-11-05 20:37:36 
Re: Print last 5 lines
gazelle@[EMAIL PROTECTED]  2007-11-05 22:03:13 
Re: Print last 5 lines
loki harfagr <loki@[EM  2007-11-06 11:33:02 
Re: Print last 5 lines
Steffen Schuler <schul  2007-11-07 00:12:08 
Re: Print last 5 lines
Steffen Schuler <schul  2007-11-07 00:19:19 
Re: Print last 5 lines
Steffen Schuler <schul  2007-11-07 00:46:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 18:19:50 CDT 2008.