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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep latest file based on date. lweegp Shell Programming and Scripting 12 04-03-2009 04:10 AM
modifying grep to get files only within last 2 hrs ragha81 Shell Programming and Scripting 3 01-11-2007 07:11 PM
modifying C file and linking back to project files bruins2005 UNIX for Dummies Questions & Answers 1 06-23-2006 12:08 AM
Perl - Appending/Modifying Excel files srinivay Shell Programming and Scripting 2 01-10-2005 06:46 AM
How can I ... (Modifying large ASCII files) hviktor UNIX for Dummies Questions & Answers 2 07-20-2001 11:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-28-2006
ragha81 ragha81 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 145
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 (permalink)  
Old 12-28-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,789
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 (permalink)  
Old 12-28-2006
ragha81 ragha81 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 145
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 (permalink)  
Old 12-28-2006
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
Oops. Nevermind
  #5 (permalink)  
Old 12-28-2006
ragha81 ragha81 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 145
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 (permalink)  
Old 04-02-2009
vpraveena vpraveena is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 7
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
Closed Thread

Bookmarks

Tags
grep or

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 02:32 AM.


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