The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep question. saurabhsinha23 UNIX for Dummies Questions & Answers 3 12-11-2007 01:58 AM
Question about GREP Adriel UNIX for Dummies Questions & Answers 16 03-22-2007 08:03 AM
Another grep question kingdbag UNIX for Dummies Questions & Answers 6 10-27-2006 02:56 AM
grep & sed question der Kopf Shell Programming and Scripting 1 11-22-2004 04:49 AM
Grep question eloquent99 UNIX for Dummies Questions & Answers 4 02-20-2003 10:49 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 11-19-2004
ssmiths001 ssmiths001 is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 41
Grep question

I have a large log file. I want to keep 1 week worth of records. This is what part of file looks like:

Oct 04 09:16:59 [INFORMATION] Order intfc ended normally on 10/04/2004 at 09:16.
Oct 04 09:16:59 [INFORMATION] ------------------------------------------------
Oct 04 09:16:59 [INFORMATION] TM: Program <Iordload> ended (normal, exit <0>).

********

WARNING: The following errors occurred running sqlldr...

SQL*Loader: Release 9.2.0.5.0 - Production on Mon Oct 4 09:16:57 2004

Oct 04 09:32:04 [INFORMATION] Access code is valid.
Oct 04 09:32:04 [INFORMATION] Task master: Program <Iordload> started.
Oct 04 09:32:04 [WARNING] Ord <B394588-SFI>: cannot modify ord that does not exist. Ord will be added with <I> status.


Is there a way to truncate the records that are less than today's date - 7 days? I think it would be easier to do if each and every record began with a date, but in this file they don't. Any help would be greatly appreciated.
  #2 (permalink)  
Old 11-19-2004
encrypted's Avatar
encrypted encrypted is offline Forum Advisor  
Registered User
  
 

Join Date: Feb 2004
Location: Oslo, Norway
Posts: 219
What seems to me that you are trying to Load records
into a database using SQL Loader.
What am I not getting is that why are you truncating the log
to have records for a week?
Are you trying to spilt the log into data of 1 week?

Enc.
  #3 (permalink)  
Old 11-19-2004
encrypted's Avatar
encrypted encrypted is offline Forum Advisor  
Registered User
  
 

Join Date: Feb 2004
Location: Oslo, Norway
Posts: 219
On second thoughts!!

If you want lines in the log which have the date exactly 1 week from todays date
you can try:

code:
Quote:

#!/bin/bash
LAST_WEEK=`perl -e '$t=localtime(time-604800);print "$t\n"';`
SEARCH_STRING=`echo $LAST_WEEK|awk '{print $2,$3}'`
grep $SEARCH_STRING <path to your_log_file>
Hope That helps
enc.
  #4 (permalink)  
Old 11-19-2004
ssmiths001 ssmiths001 is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 41
This log file gets auto generated by another system of ours. I was just trying to point out that in this file, not all of the lines have a timestamp associated with them. Maybe it would be easier and better if I could just figure out how to chop off the first X rows from the file.
  #5 (permalink)  
Old 11-19-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
Once a night do something like...

mv file.6 file.7
mv file.5 file.6
mv file.4 file.5
mv file.3 file.4
mv file.2 file.3
cp file file.2
> file
  #6 (permalink)  
Old 11-19-2004
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
U can write the log file every day to a new different file based on date format ;


If u do n't have a control of this ......,

Is there any pattern of 'first line' it prints on every day ; Find out the line number using 'grep' ; Let's say that is 'm'

Try for the second day using grep ; Let's say the second day starts with line number 'n'

Seperate the first day logs using head and tail .... between

m and n-1 lines.




Repeast the same thing for other 6 days.

Hope this helps.
Closed Thread

Bookmarks

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 06:45 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