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 > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-25-2008
prsshini prsshini is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 20
get the latest file by reading the date in the filename.

Hi,
I grep for a pattern in a list of files.

"grep -i -l $pattern *.datx*"

it may give me n number of files.
say for eg, it gives me 2 files.
lock_eicu_20071228_00000000.dat_20071228_05343100
lock_eicu_20080501_00000000.dat_20080501_05343900

out of these 2 files I need to get the latest file according to the date present after the .dat extn. As 20071228 is older than 20080501, i need to get the second file.

so in the above eg, i need to get the filename
lock_eicu_20080501_00000000.dat_20080501_05343900
can u please help.