LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 01-11-2010, 09:06 AM   #1
rhinoict
LQ Newbie
 
Registered: Jan 2010
Posts: 2

Rep: Reputation: 0
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?
 
Old 01-11-2010, 09:25 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,632

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by rhinoict View Post
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.
Code:
awk '{print $9}'
 
Old 01-11-2010, 09:37 AM   #3
SethsdadtheLinuxer
Member
 
Registered: Jun 2007
Posts: 152

Rep: Reputation: 37
here's a nifty link
http://forums13.itrc.hp.com/service/...readId=1154641
the awk one-liner
awk 'END {print}' file
sed '$!d' file (- bonus)
 
Old 01-11-2010, 09:40 AM   #4
cpplinux
Member
 
Registered: Dec 2009
Posts: 37

Rep: Reputation: 17
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.
 
Old 01-11-2010, 10:46 AM   #5
vrmartin2
Member
 
Registered: Dec 2009
Location: NE Ohio
Distribution: Open SUSE
Posts: 43

Rep: Reputation: 19
Why not use tail?

Just curious: Why use awk when you can use "tail -1 <file>"?
 
Old 01-11-2010, 10:49 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by vrmartin2 View Post
Just curious: Why use awk when you can use "tail -1 <file>"?
Almost certainly, because he/she meant columns and not rows.
 
Old 01-11-2010, 11:29 AM   #7
rhinoict
LQ Newbie
 
Registered: Jan 2010
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
  


Reply

Tags
awk



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk question on handling *.CSV "text fields" in awk jschiwal Programming 8 05-27-2010 06:23 AM
awk , I need help for awk, just a display function mcandy General 1 12-15-2008 12:21 PM
using awk on a awk result jpgauvin Programming 1 12-15-2008 03:57 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
Some comments on awk and awk scripts makyo Programming 4 03-02-2008 05:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration