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)
srcfile.c
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 un
> 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
h
> How about
>cat log|grep -v -E [[:alnum]]'{2096}'>> log.bak
OK< but you can miss the cat out
grep -v -E [[:alnum]]'{2096}' log >> log.bak
But I confess I've no idea how that works, I've never
seen that notation in a grep before! Checking man reveals
an "extended regex" which I interpret
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
t; 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!
> >
> >dstfile.w
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
J"o!
--
You're at the end of the road again.
___
Tutor maillist - Tutor@python.org
htt
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 Gaul
-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 enormousl
> About the efficiency, why do u need python at all...
> How abt a simple shell command
>cat httpd-access.log>>log.bak
>
Because that would be a copy, well actually an append...
cp httpd-access.log log.bak
would be better!
But the OP wanted to strip out long lines in transit
not ju
> 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
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 effici
On Mon, 7 Feb 2005, 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 t
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 to the appropriate file
14 matches
Mail list logo