File Handling


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users File Handling
# 1  
Old 10-09-2008
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  
Old 10-09-2008
Have you considered using logrotate tools? I dont know if it deals with such size logfile but maybe worth enquiry...
# 3  
Old 10-21-2008
no logrotate

Iam not trying to use a tool.

Iam trying to develop a script myself.

Any other ideas will be appreciated.

Thanks
# 4  
Old 10-21-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File handling

Hi All, I need to extract the data from the text file. The data of the text file is shown below #L 0.000017 4.329939 0.000017 4.716267 r7.9 P 1 1;Net=IN32 The extracted data should be IN32. Could anyone help to script in c shell.? (4 Replies)
Discussion started by: gopishrine
4 Replies

2. UNIX for Dummies Questions & Answers

File handling

I have a file 1 298167 298168 1093209 1093210 1422663 I want to write a code where in I want to read contents of above file like first read is 1 second read is 298167 Substract second read from first and if this is greater than or less than 99,999. Similarly I want to traverse thru... (3 Replies)
Discussion started by: Guru148
3 Replies

3. UNIX for Dummies Questions & Answers

File Handling

Hi Team, I am trying to cut a large file into multiple files. It has Header 50,050 records Trailer ------------------------------------------- I need to cut the files into multiple files of 1000 records and should have the same header and trailer as the original files. ... (4 Replies)
Discussion started by: Gurkamal83
4 Replies

4. Shell Programming and Scripting

ksh file handling

Specifically on RHEL 5.7. When does the underlying ksh process open and close files? Every time they're accessed, or as little as possible? Say you have some script like: CreateFiles() { grep "<VALUE1>" ${infile} >> ${outfile} grep "<VALUE2>" ${infile} >> ${outfile} ...... (4 Replies)
Discussion started by: CarloM
4 Replies

5. Programming

Perl help for file handling

$# some text $$ some text $@ some text $$. some text Mg1 some text Mg2 some text . . . Mg10 some text The above 10 lines are to be extracted except the lines starting from $#,$$.,... (4 Replies)
Discussion started by: baig.abdul
4 Replies

6. Shell Programming and Scripting

UNIX File handling -Issue in reading a file

I have been doing automation of daily check activity for a server, i have been using sqls to retrive the data and while loop for reading the data from the file for several activities. BUT i got a show stopper the below one.. where the data is getting store in $temp_file, but not being read by while... (1 Reply)
Discussion started by: KuldeepSinghTCS
1 Replies

7. UNIX for Advanced & Expert Users

File handling

my input for a script is another csv file but in that file say 7 lines are there ... how can i get line by line to that input for example : >cat link.csv www.yahoo.com,yahoo www.google.com,google www.unix.com,unix another file in that file i need to ping the above links ... (2 Replies)
Discussion started by: ponmuthu
2 Replies

8. UNIX for Advanced & Expert Users

please help me in file handling

sir i have to get first line from a file for example >cat file1 abc zxc asd adsf from that file1 i need only first line expected result >abc please help me ! (1 Reply)
Discussion started by: ponmuthu
1 Replies

9. Programming

file handling

Hi all, I got a little issue here. Imagine that I have more than one process accessing one file. Is it possible to know which process(es) are accessing that file when I open the file?? Thanks for the help. Best regards, Ernesto (2 Replies)
Discussion started by: ninjanesto
2 Replies

10. Programming

File Handling in C

Hi all, I have a problem in handling files through C. here is the problem im having: i will query the database (for instance consider employees table ) for empno,ename,job,salary fields.The query returns me some 100 of rows. now i need to place them in a file in row wise pattern as they... (3 Replies)
Discussion started by: trinath
3 Replies
Login or Register to Ask a Question