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)

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

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 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 enormously long line

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 Gauld

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 Jo! -- You're at the end of the road again. ___ Tutor maillist - Tutor@python.org

Re: [Tutor] manipulating a file

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

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 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

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 unix shell