The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File handling in Script raman1605 Shell Programming and Scripting 2 10-08-2008 09:46 AM
file handling ninjanesto High Level Programming 2 12-27-2006 11:35 AM
file handling with ksh scripting gfhgfnhhn Shell Programming and Scripting 1 07-03-2006 10:55 AM
File Handling in C trinath High Level Programming 3 01-19-2006 11:00 PM
KSH File Handling madtim Shell Programming and Scripting 2 08-27-2002 03:08 PM

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 10-09-2008
baanprog baanprog is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 22
File Handling

Hi,

I have a log file which runs into 3 to 5 GB.

We store this typically for 6 months. When a new month starts we move the previous month into a 9 month back up log (file.9m) and delete the last month of the 9 month back up.

Iam using awk to find the data and cat to join the files like below

BEGIN { FS = "|"}

{ if (($5 == "09") && ($6 == "08")) print $0 >> "/file.1m";
}

END { print "script processed " NR}

in the above $5 is month and $6 is the year and the log file has pipe separated columns

cat /file.6m /new.log > /file.temp
mv /file.temp /new.log

the file.6m is the back up file when a new month starts and the new.log is the running log.

similarly I extract file.1m(last month) from file.6m and file.8m ( eight months without the last month from the file.9m) and join using cat as above.

This process though is NOT neat, is yielding the result.

I would like to know if there is any better of doing this. Since the file is really large sometimes i find the data jumbled up.

Appreciate your inputs.
  #2 (permalink)  
Old 10-09-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,585
Have you considered using logrotate tools? I dont know if it deals with such size logfile but maybe worth enquiry...
  #3 (permalink)  
Old 10-21-2008
baanprog baanprog is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 22
no logrotate

Iam not trying to use a tool.

Iam trying to develop a script myself.

Any other ideas will be appreciated.

Thanks
  #4 (permalink)  
Old 10-21-2008
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 208
rather than storing the entire nine months logs in one file, have you considered one file for each month? then it would be trivial to move each month "up" at month end:

<top of head mod>

Code:
for FEXT in  8 7 6 5 4 3 2 1
do
OLDEXT=$((FEXT + 1))
OLDFILE=file.$OLDEXT
NEWFILE=file.FEXT
[ -f $NEWFILE ] && mv $NEWFILE $OLDFILE
done

which will move each file "up" by one each time it is run, knocking the last file off the end (actually overwriting it with the months before).
does this help?

Last edited by wempy; 10-21-2008 at 10:04 AM.. Reason: replaced down with up for clarity
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 04:57 PM.


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