- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- awk to print last line
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
Discussions
Discussions
Discussions
Forums
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
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-21-2007 12:08 AM
тАО08-21-2007 12:08 AM
how can I get awk to print the last line and first field from a command output?
I know I can do :
command | awk '/rows/ {print $1}'
but I was wondering is there another method incase there are mulitple lines containing rows?
command output is:
USER_NAME RESPONSIBILITY
--------------- ------------------------------
abc
USER_NAME RESPONSIBILITY
--------------- ------------------------------
def
141 rows selected.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2007 12:16 AM
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2007 12:19 AM
тАО08-21-2007 12:19 AM
Re: awk to print last line
that will do me!
Thanks Pete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2007 12:21 AM
тАО08-21-2007 12:21 AM
Re: awk to print last line
awk 'END{print}'
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2007 12:21 AM
тАО08-21-2007 12:21 AM
Re: awk to print last line
With Perl that's easy:
# command|perl -nlae 'print $F[0] if eof'
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2007 12:24 AM
тАО08-21-2007 12:24 AM
Re: awk to print last line
...I should hasten to add, that if you want the whole last line, simply do:
# command|perl -nle 'print if eof'
...otherwise what I gave above prints the _first_ filed of the _last_ line only.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2007 12:27 AM
тАО08-21-2007 12:27 AM
Re: awk to print last line
command | awk '
{
SAVE = $1
}
END { print SAVE } '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2007 12:29 AM
тАО08-21-2007 12:29 AM
Re: awk to print last line
Thank you everyone.
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2007 12:35 AM
тАО08-21-2007 12:35 AM
Re: awk to print last line
awk 'END { print $1 } '