Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create log file from old log file

Status
Not open for further replies.

we2aresame

Technical User
Feb 10, 2003
128
CA
Hi, all,
A software create log daily, the log file will be copied to a new file like log.1...log.100 if the log achieve a size limit. What I need is to keep the log by monthly not by size, there are date information in each line of the the log, how can I create log file by monthly from the log files. Thanks.
 
First, pls don't create multiple threads.

Second, give us a sample of your log file and someone might be able to get you started.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi, vgersh,thanks for your suggestion. My log file was created by another software which I cannot control. I tried to use a script to create a new log file by month,
Old log file,
server1 [03/May/2003:20:55:29
server1 [03/May/2003:20:55:30
server1 [03/Jun/2003:20:55:31
server1 [03/Jun/2003:20:55:31
New log file1
server1 [03/May/2003:20:55:29
server1 [03/May/2003:20:55:30
New log file2
server1 [03/Jun/2003:20:55:31
server1 [03/Jun/2003:20:55:31
Anybody can give me a help, thanks.
 
Try something like this:
Code:
awk -F/ '
NR==1{m=$2;out=&quot;log.&quot;$2}
$2!=m{close(out);out=&quot;log.&quot;$2}
{print > out}
' OldLogFile

Hope This Help
PH.
 
sorry, what I wrote maybe confuse you.
in the old log file, for exampel, logfile1, there are lines like:
server1 [03/May/2003:20:55:29
server1 [03/May/2003:20:55:30
server1 [03/Jun/2003:20:55:31
server1 [03/Jun/2003:20:55:31
I want to create a 2 new log file,
in newfile.may, there should be lines
server1 [03/May/2003:20:55:29
server1 [03/May/2003:20:55:30
in newfile.Jun, there should be lines
server1 [03/Jun/2003:20:55:31
server1 [03/Jun/2003:20:55:31
Anyway, thank you very much.

 
Try something like this:
Code:
awk -F/ '
NR==1{m=$2;out=&quot;newfile.&quot;$2}
$2!=m{close(out);m=$2;out=&quot;newfile.&quot;$2}
{print > out}
' logfile1

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top