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
parse an arpwatch file and retain most recent mac CM64 Shell Programming and Scripting 8 04-12-2007 12:21 AM
Get the most recent file from a remote server anujairaj UNIX for Dummies Questions & Answers 5 09-27-2006 10:31 AM
Changing name of most recent file warpmail AIX 1 02-15-2006 07:34 PM
reading directory for most recent file? duncan_glover UNIX for Dummies Questions & Answers 3 08-22-2002 07:26 AM
Most Recent File script josborn777 Shell Programming and Scripting 1 03-29-2002 05:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-22-2006
anujairaj anujairaj is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 13
getting the most recent file

Hi,
I have files coming in every day with that days timestamp like:
nameyyyymmddhhmmss.ext.
I need the most recent one and so i am using

cat `ls -t name*|head -1 ` > temp

i am sorting the files in the decending order and am copying the most recent one into a temp file.
It works at times but sometimes it does not.
Is there a better way to do it?
I dont want to compare it to todays absolute date ;I just want the most recent file.
any suggestions will be appreciated.
thanks
  #2 (permalink)  
Old 06-22-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Code:
ls -1 * | sed 's/^[^0-9][^0-9]*\([0-9][0-9]*\).*/\1 &/' | sort -n | cut -d ' ' -f2- | tail -1

Last edited by vgersh99; 06-22-2006 at 03:03 PM..
  #3 (permalink)  
Old 06-22-2006
anujairaj anujairaj is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 13
Can you explain the
[^0-9]*\([0-9][0-9]*\).*/\1 &/'
part?
thanks
  #4 (permalink)  
Old 06-22-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Quote:
Originally Posted by anujairaj
Can you explain the
[^0-9]*\([0-9][0-9]*\).*/\1 &/'
part?
thanks
1. anything BUT the numberS followed by
2. any number of digits followed by
3 anything

output 'bullet item '2' followed by ' ' and followed by the entire string
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 01:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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