The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
generated CSV file on AIX mpang_ Shell Programming and Scripting 0 09-05-2006 08:01 PM
Need a script to Append date to generated .txt file prince_of_focus Shell Programming and Scripting 2 08-01-2006 11:51 AM
How to FTP a file generated at UNIX Box to NT Box Ruchir UNIX for Advanced & Expert Users 2 08-11-2005 02:55 AM
Automatically Rename Last Generated File pieter023 Shell Programming and Scripting 2 05-25-2005 11:14 AM
Core File Not Being Generated in AIX S.P.Prasad High Level Programming 6 09-23-2003 02:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-18-2006
Registered User
 

Join Date: Jul 2006
Posts: 145
get the last generated log file

Hi

I need to get the last generated file in a directory using ls -ltr. I need to store the output of ls -ltr in a variable.

it will like this

$xyz = -rw-rw-r-- 1 sblp003 siebel 1060 Dec 18 13:33

from this output, I need to do a substring to get this value alone "Dec 18 13:33". Can you guys please help me write a shell script to implement this logic.

I am not too familiar with shell scripting.

Thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 12-18-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
xyz=$(ls -ltr | grep ^- | tail -1 | awk ' { print $6,$7,$8 } ')
Reply With Quote
  #3  
Old 12-19-2006
Registered User
 

Join Date: Jul 2006
Posts: 145
anbu

thanks for the reply. small modification to myy above requirement. I need to do ls -ltr for files starting with this 'eCustomerCME*'. Pls help me do this. thanks a lot!!
Reply With Quote
  #4  
Old 12-19-2006
Registered User
 

Join Date: Aug 2006
Posts: 41
Try this, just change yoru "-" to "eCustomerCME" and take away the tail and awk

Code:
xyz=$(ls -ltr | grep ^eCustomerCME*)
Reply With Quote
  #5  
Old 12-19-2006
Registered User
 

Join Date: Jul 2006
Posts: 145
i tried that, but is returning a blank result.. any other suggestions plz!
Reply With Quote
  #6  
Old 12-19-2006
Registered User
 

Join Date: Jul 2006
Posts: 145
anbu

ur code is working exactly as i expected. thanks! just a small modification, it has to do a ls -ltr only for files starting with 'eCustomerCME'. I would basicall search for eCustomerCME*. thanks
Reply With Quote
  #7  
Old 12-19-2006
Registered User
 

Join Date: Jul 2006
Posts: 189
xyz=$(ls -ltr eCustomerCME* | grep ^- | tail -1 | awk ' { print $6,$7,$8 } ')
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0