The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 11:23 AM
Loop through files in dir, omit file with latest date stringzz Shell Programming and Scripting 2 12-04-2007 02:04 PM
Picking the file based on Date..Requirement sureshg_sampat Shell Programming and Scripting 5 06-06-2007 05:51 AM
Grabbing lines out of a file based on a date bsp18974 Shell Programming and Scripting 2 07-17-2006 08:58 AM
File management based on date created Geehog_Rare UNIX for Dummies Questions & Answers 1 01-30-2006 04:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-17-2006
lweegp lweegp is offline
Registered User
  
 

Join Date: Oct 2005
Location: singapore
Posts: 107
Smile grep latest file based on date.

hi all,

not sure if this has been posted b4 but i try to search but not valid.

this is my question:

when i do a ls -ltr there will be a list generated as follows:

-rw-r--r-- 1 root sys 923260 Jan 10 04:38 FilePolling.41025.083TL021.xml
-rw-r--r-- 1 root sys 1761337 Jan 10 04:40 FilePolling.41073.114TL020.xml
-rw-r--r-- 1 root sys 76 Jan 11 04:32 FilePolling.41423.024TL022.xml
-rw-r--r-- 1 root sys 82 Jan 11 04:40 FilePolling.41681.110TL022.xml
-rw-r--r-- 1 root sys 1136429 Jan 12 04:36 FilePolling.42235.068TL020.xml
-rw-r--r-- 1 root sys 82 Jan 12 04:40 FilePolling.42301.110TL022.xml
-rw-r--r-- 1 root sys 791807 Jan 13 04:31 FilePolling.42629.018TL024.xml

my question here is how do i grep the latest file (in this case the file will be the 13 Jan)?

can it be done?

thanks.
  #2 (permalink)  
Old 01-17-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Simplest could be

ls -latr

If you looking for an xml file then, ls -latr | grep '.xml$'
  #3 (permalink)  
Old 01-17-2006
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
grep "something" `ls -tr | tail -1`

Cheers
ZB
  #4 (permalink)  
Old 01-17-2006
lweegp lweegp is offline
Registered User
  
 

Join Date: Oct 2005
Location: singapore
Posts: 107
hi there,

thanks for the solution but dont think it's working.

what i meant is i want the latest file to be shown not the whole list of them ie:

-rw-r--r-- 1 root sys 791807 Jan 13 04:31 FilePolling.42629.018TL024.xml
  #5 (permalink)  
Old 01-17-2006
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Now I see what you want.

ls -latr | tail -1
-or-
ls -latr | sed -n '$p'

Cheers
ZB
  #6 (permalink)  
Old 01-17-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by zazzybob
Now I see what you want.

ls -latr | tail -1
-or-
ls -latr | sed -n '$p'

Cheers
ZB
I think the option a can be done away with. It would be ls -ltr | tail -1
  #7 (permalink)  
Old 01-17-2006
lweegp lweegp is offline
Registered User
  
 

Join Date: Oct 2005
Location: singapore
Posts: 107
hey guys,

its working...many thanks.

wee
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0