import os
srcfile = open('/var/log/httpd-access.log.bak', 'r')
dstfile = open('/var/log/httpd-access.log', 'w')
while 1:
lines = srcfile.readlines()
if not lines: break
#print lines
for i in lines:
if len(i) 2086:
#print i
dstfile.write(i)
Hi,
I do see a problem.
The script is fine, the problem lies else where.
Your script is trying to write log.bak to log, it
should b other way round.
i.e
srcfile = open('/var/log/httpd-access.log', 'r')
dstfile = open('/var/log/httpd-access.log.bak', 'w')
hope that fixes it.
About the
running the following with print i uncommented does print each line
to
stdout. but it doesn't write to the appropriate file...
Does it do anything?
BTW YOu don;t need to touch a file, the 'w' parameter will
create a new file if one doesn't exist.
c) I originally wanted to delete lines over
-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED]
Sent: Monday, February 07, 2005 2:49 PM
To: Reed L. O'Brien; tutor@python.org
Subject: Re: [Tutor] manipulating a file
You should add a newline character otherwise you will just
get one enormously long line
How about
cat log|grep -v -E [[:alnum]]'{2096}' log.bak
The issue is - will unix shell command be any more
efficient than a python script??
Also i used append because i gathered that the user
will not want to erase the previous logs. He is free
to use a single if he does.
--- Alan Gauld
On Mon, Feb 07, 2005 at 01:01:29PM -0800, Shitiz Bansal wrote:
How about
cat log|grep -v -E [[:alnum]]'{2096}' log.bak
UUOC (Useless Use Of Cat)
SCNR
Jo!
--
You're at the end of the road again.
___
Tutor maillist - Tutor@python.org
, February 07, 2005 2:49 PM
To: Reed L. O'Brien; tutor@python.org
Subject: Re: [Tutor] manipulating a file
You should add a newline character otherwise you will just
get one enormously long line!
dstfile.write(i+'\n')
In these cases, I've taken to doing
print dstfile
Reed L. O'Brien wrote:
I want to read the httpd-access.log and remove any oversized log records
I quickly tossed this script together. I manually mv-ed log to log.bak
and touched a new logfile.
running the following with print i uncommented does print each line to
stdout. but it doesn't write
without the explicit newlines in file.write(i), could it be that the
file was closed before the write buffer was ever flushed?
No because close() was called explicitly, which does a flush first...
Alan G.
___
Tutor maillist - Tutor@python.org
I aplogise for a typo...
Please read the command as:
cat log|grep -v -E [[:alnum]]'{2096,}' log.bak
note the missing comma in the previous command.
--- Shitiz Bansal [EMAIL PROTECTED] wrote:
How about
cat log|grep -v -E [[:alnum]]'{2096}' log.bak
The issue is - will unix shell
10 matches
Mail list logo