- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to display last line with awk?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 08:58 PM
08-14-2005 08:58 PM
---
The above can display forth line of the file /tmp/test.log. How to display the last line... NR==?
Thanks
Eric
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 09:09 PM
08-14-2005 09:09 PM
Re: How to display last line with awk?
try
'END {print $1}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 09:09 PM
08-14-2005 09:09 PM
Re: How to display last line with awk?
If not then use tail
tail -1 /tmp/test.log
Cheers,
Kasper
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 09:11 PM
08-14-2005 09:11 PM
Re: How to display last line with awk?
not sure how to use awk to display last line, but using tail:
# tail -n 1 /tmp/test.log
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 09:18 PM
08-14-2005 09:18 PM
Re: How to display last line with awk?
tail -1 /tmp/test.log
good luck,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 02:35 AM
08-15-2005 02:35 AM
Re: How to display last line with awk?
tail -1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 02:36 AM
08-15-2005 02:36 AM
Re: How to display last line with awk?
tail -1
This is 1 line to get what you want. Doing so with awk will be more lines and more complexity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 05:55 AM
08-15-2005 05:55 AM
Re: How to display last line with awk?
awk '{saveit=$0;}END{print saveit}' /tmp/test.log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 06:35 AM
08-15-2005 06:35 AM
Re: How to display last line with awk?
# tail -1
# sed -n '$p'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 06:40 AM
08-15-2005 06:40 AM
Re: How to display last line with awk?
will give you the entire last night of the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 07:05 AM
08-15-2005 07:05 AM
Re: How to display last line with awk?
it depends from what you want to get.
awk 'END {print $1}' ... will give you a field (only) of the last "readable" line, but
awk 'END {print $0}' ... will give you the really last line - EOT (just something like nothing). tail is a good tool to get what you want.
HTH
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2005 01:34 AM
08-16-2005 01:34 AM
Re: How to display last line with awk?
# awk '{lst=$0} END{print lst}'
awk 'END {print $0}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2005 01:59 AM
08-16-2005 01:59 AM
Re: How to display last line with awk?
Yes,
awk 'END {print $0}' /tmp/test.log
don't work but,
awk 'END {print $1}' /tmp/test.log
does work (and, also $2 $3 etc.).
I used $1 as it was used in the initial example.
awk 'NR==4{print $1}' /tmp/test.log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2005 06:45 PM
08-16-2005 06:45 PM
Re: How to display last line with awk?
Yes, the following can display the last line
------------
awk '{saveit=$0;}END{print saveit}' /tmp/test.log
------------
However, I would like to get the first field of the last line..... How can I do?
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2005 06:58 PM
08-16-2005 06:58 PM
Re: How to display last line with awk?
# awk 'END{ print $1 }' /tmp/test.log
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2005 04:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2005 07:40 AM
08-17-2005 07:40 AM
Re: How to display last line with awk?
My previous reply do exact what you ask for, but, you can also try :
awk '{saveit=$0;}END{getline saveit ; print $1}' /tmp/test.log
There is always more then one way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2005 08:33 PM
08-18-2005 08:33 PM
Re: How to display last line with awk?
# tail -1 .profile | cut -d" " -f1