Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-11-2010, 09:06 AM
|
#1
|
LQ Newbie
Registered: Jan 2010
Posts: 2
Rep:
|
awk ?
I have a .out file that has this information:
-rw-r--r-- 1 root system 1763444 Sep 30 18:11 log.td-ict-111
I just want a simple script to list only the last row of informatin (the log. names) How can I do this with awk?
|
|
|
01-11-2010, 09:25 AM
|
#2
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,728
|
Quote:
Originally Posted by rhinoict
I have a .out file that has this information:
-rw-r--r-- 1 root system 1763444 Sep 30 18:11 log.td-ict-111
I just want a simple script to list only the last row of informatin (the log. names) How can I do this with awk?
|
The man page for awk has all the options on it, and Google's got lots of examples, if you looked.
Awk, by default, splits things on white-space. So if you put your string into it, you want to print out field 9, based on your example.
|
|
|
01-11-2010, 09:40 AM
|
#4
|
Member
Registered: Dec 2009
Posts: 37
Rep:
|
NF means number of fields in awk. You can use $NF to refer to the last field.
Code:
awk '{print $NF}' myfile.out
Edit: Sorry, I thought you meant the last column. For the last row, go for SethsdadtheLinuxer's solution.
Last edited by cpplinux; 01-11-2010 at 09:44 AM.
|
|
|
01-11-2010, 10:46 AM
|
#5
|
Member
Registered: Dec 2009
Location: NE Ohio
Distribution: Open SUSE
Posts: 43
Rep:
|
Why not use tail?
Just curious: Why use awk when you can use "tail -1 <file>"?
|
|
|
01-11-2010, 10:49 AM
|
#6
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by vrmartin2
Just curious: Why use awk when you can use "tail -1 <file>"?
|
Almost certainly, because he/she meant columns and not rows.
|
|
|
01-11-2010, 11:29 AM
|
#7
|
LQ Newbie
Registered: Jan 2010
Posts: 2
Original Poster
Rep:
|
pixellany was correct I was needing the last column of data from the .out file. The command that cpplinux suggested (awk '{print $NF}' myfile.out) worked perfectly in my applicaion.
Thanks to all for the help 
|
|
|
All times are GMT -5. The time now is 02:15 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|