Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print last 10 lines from file using awk

Status
Not open for further replies.

Mnaim

Technical User
Apr 13, 2001
1
NO
Im new awk user. Any body can help me to print last 10 lines from file using awk
 
Hi Mnaim-

You can use this unix command:

tail lnfile # prints last 10 lines by default

tail -30 lnfile # prints last 30 lines

You can also use this short awk script:


awk '

{line[NR] = $0}

END { print "Here are the last 10 lines of file: "FILENAME"\n\n"
i = NR - 9
while ( i <= NR ) {
print line
i++
}
}' lnfile | more

Hope this helps you!


flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top