modifying grep to return latest files

Hi guys,

I currently use the below mwntioned grep statemen to get the timestamp of the last generated file in the directory.

(ls -ltr eCustomerCME* | grep ^- | tail -1 | awk ' { print $6,$7,$8 } ')

I need to modify this grep to search for files generated only within last 2 hrs. Can you pls suggest how to achieve that by modifying my grep or by some other method in my shell script. pls help me guys.. this is urgent.

thanks in advance

assume the time is now 09:46 Dec 28
12280746 is two hours earlier on Dec 28

 touch  -t 12280746 dummy
find .  -name 'eCustomerCME*' -newer dummy  -type f  -exec ls -ltr {} \; | tail -1 | awk ' { print $6,$7,$8 } ')

jim.. thanks for the reply.

i would like to put a variable like (current time - 2hrs) instead of hard coding the value like 1228. how do i do that?

pls advice me on this.

Thanks

Oops. Nevermind :slight_smile:

thanks a lot for ur help, guys. Jim your command works exactly as I expected. thanks a lot.

I used this posting in the forums to subtract hours from the date

Command we tried using to grep ERROR from lastest 1 log files from 5 logs files available in that particular directory is:
grep ERROR 'ls -ltr | tail -1'

but this command is not working.. for me its saying.. cannot open DistributeImageFilesToTarget_10_dataLocations_PhillipinesDataLocations.xml.log

if i give ls -lrt for all the files in that diretory

-------r-- 1 egdevbb intdev 5022 Apr 2 05:13 DistributeDataFilesToTarget_4_dataLocations_ChinaDataLocations.xml.log
-------r-- 1 egdevbb intdev 1672 Apr 2 05:14 DistributeImageFilesToTarget_14_dataLocations_WHQDataLocations.xml.log
-------r-- 1 egdevbb intdev 7480 Apr 2 05:15 DistributeImageFilesToTarget_60_dataLocations_IndonesiaDataLocations.xml.log
-------r-- 1 egdevbb intdev 2113 Apr 2 05:34 DistributeImageFilesToTarget_8_dataLocations_MalaysiaDataLocations.xml.log
-------r-- 1 egdevbb intdev 2107 Apr 2 05:39 DistributeImageFilesToTarget_10_dataLocations_PhillipinesDataLocations.xml.log