modifying grep to return latest files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting modifying grep to return latest files
# 1  
Old 12-28-2006
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
# 2  
Old 12-28-2006
assume the time is now 09:46 Dec 28
12280746 is two hours earlier on Dec 28
Code:
 touch  -t 12280746 dummy
find .  -name 'eCustomerCME*' -newer dummy  -type f  -exec ls -ltr {} \; | tail -1 | awk ' { print $6,$7,$8 } ')

# 3  
Old 12-28-2006
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
# 4  
Old 12-28-2006
Oops. Nevermind Smilie
# 5  
Old 12-28-2006
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

http://unix.com/showthread.php?t=190...btracting+date
# 6  
Old 04-02-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep a pattern & Email from latest logs

MyLOG: 2017/11/12 17:01:54.600 : Error: LPID: 3104680848 WRONG CRITERIA FOUND. tRealBuilder::Generate Output Required: If Ke word "WRONG CRITERIA FOUND" in latest log ( logs are regularly generating - real time) mail to us once mailed wait for 2 hours for second mail. mail subject... (3 Replies)
Discussion started by: vivekn
3 Replies

2. Shell Programming and Scripting

Modifying Variables in Files

hi list, I am currently looking to develop an installation script which writes out .conf files based on existing .conf files according to variables which are set in a settings file. For example I have a settings file like so: ip=192.168.1.1 hosts=localAnd I want to read a file which... (3 Replies)
Discussion started by: landossa
3 Replies

3. Shell Programming and Scripting

Grep the Content of a LOG File which has latest Date and Time

Hi All, Need a small help. I have a log file which keeps updating for every Minute with multiple number of lines. I just want to grep few properties which has latest Date and Time to it. How do i do it? I wanted to grep a property by name "Reloading cache with a maximum of" from the... (4 Replies)
Discussion started by: nvindraneel
4 Replies

4. Shell Programming and Scripting

script to grep latest outofmemory string from the logs

I have requirement to prepare script which will grep for latest outofmemory message from the logs. I have used following command to grep the string from the logs,this script is not effective when logs are not getting updated as it will grep for old message. f=catalina.out var=`tail -10 $f |... (17 Replies)
Discussion started by: coolguyamy
17 Replies

5. Shell Programming and Scripting

Help with modifying files

Hello everyone, I have some data files, with mixed header formats. the sample for the same is: >ABCD76567.x1 AGTCGATCGTAGTCGTAGCTGT >ABCD76567.y1 AGTCGATCGTAGTCGTAGCTGT >ABCD76568.x1 pair_info:898989 AGTCGATCGTAGTCGTAGCTGT >ABCD76568.y1 pair_info:893489 AGTCGATCGTAGTCGTAGCTGT... (2 Replies)
Discussion started by: ad23
2 Replies

6. UNIX for Dummies Questions & Answers

| help | unix | grep - Can I use grep to return a string with exactly n matches?

Hello, I looking to use grep to return a string with exactly n matches. I'm building off this: ls -aLl /bin | grep '^.\{9\}x' | tr -s ' ' -rwxr-xr-x 1 root root 632816 Nov 25 2008 vi -rwxr-xr-x 1 root root 632816 Nov 25 2008 view -rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies

7. Shell Programming and Scripting

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... (12 Replies)
Discussion started by: lweegp
12 Replies

8. Shell Programming and Scripting

Modifying command for Tar.gz Files.

:) Hi, I use the following command to search for a string in all the files in the directories and sub directories. find . -type f -print | xargs grep bermun@cial.net Can someone please cite a method wherin I can find the entries from a list of 300-500 *.gz files by modifying the above... (2 Replies)
Discussion started by: openspark
2 Replies

9. Shell Programming and Scripting

modifying grep to get files only within last 2 hrs

Hi gurus I am currently using the below mentioned grep to find timestamp of last generated log file. touch -t $time_search dummy ecust_time_stamp=$(find . -name 'eCustomerCME*' -newer dummy -type f -exec ls -ltr {} \; | tail -1 | awk ' { print $6,$7,$8 } ') I calculate... (3 Replies)
Discussion started by: ragha81
3 Replies

10. UNIX for Dummies Questions & Answers

How can I ... (Modifying large ASCII files)

Hi Everybody! Situation: I have a large ASCII file (for example: 1-2 Mbytes) without linebreaks (\n). Task: I like inserting linebreaks after all 420 digits (byte). (pattern: *\n*\n*\n...etc.) My problem: How? :-) I like using shell script or (maybe) AWK (short) program. Please,... (2 Replies)
Discussion started by: hviktor
2 Replies
Login or Register to Ask a Question