Re: [Tutor] manipulating a file

2005-02-08 Thread Jacob S.
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

Re: [Tutor] manipulating a file

2005-02-07 Thread Shitiz Bansal
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

Re: [Tutor] manipulating a file

2005-02-07 Thread Alan Gauld
> 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

Re: [Tutor] manipulating a file

2005-02-07 Thread Alan Gauld
> 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

Re: [Tutor] manipulating a file

2005-02-07 Thread Kent Johnson
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

Re: [Tutor] manipulating a file

2005-02-07 Thread Mike Bell
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

Re: [Tutor] manipulating a file

2005-02-07 Thread Joerg Woelke
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

Re: [Tutor] manipulating a file

2005-02-07 Thread Shitiz Bansal
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

RE: [Tutor] manipulating a file

2005-02-07 Thread Smith, Jeff
-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

Re: [Tutor] manipulating a file

2005-02-07 Thread Alan Gauld
> 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

Re: [Tutor] manipulating a file

2005-02-07 Thread Alan Gauld
> 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

Re: [Tutor] manipulating a file

2005-02-07 Thread Shitiz Bansal
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

Re: [Tutor] manipulating a file

2005-02-06 Thread Danny Yoo
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

[Tutor] manipulating a file

2005-02-06 Thread Reed L. O'Brien
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