Re: Multiple files editing



The carbonbased lifeform GT inspired alt.os.linux with:
[..]
So, from a bat file containing :

call something

I wish to replace it by :

echo (options) something >> logfile
call something
echo (options) out of something >> logfile


Something like this?
#v+
#!/usr/bin/env python

import re, os, sys

f1 = open(os.argv[1],rb)
f2 = open(os.argv[2],wb)
call = re.compile('^call\s+(.*)')
preCall = "echo (options) something >> logfile"
postCall = "echo (options) out of something >> logfile"

for line in f1:
if call.match(line):
f2.write(preCall)
f2.write(line)
f2.write(postCall)
else:
f2.write(line)

f1.close()
f2.close()
#v-

I'm sure a oneliner perl/awk/bash can be made, but I like my scripts
readable, and I don't care much for a 50 bytes saving in diskspace..

If there was a way to log call errors as well, life would be nice.

You can at least test if the called object exists before calling, but
afaik a 'call' is like an 'exec' in Unix shell, it forkes a new process,
so the parent is stopped, and therefor can not log data from the child.

It seems DOS is a little poor in terms of utilities. I could write a
fortran proggy but if there was a simpler way under linux, which is
often the case, that would be nice.

Python runs just as well in Windows, and there is also a DOS version.

Theo
--
theo at van-werkhoven.nl ICQ:277217131 SuSE Linux
linuxcounter.org: 99872 Jabber:muadib at jabber.xs4all.nl AMD XP3000+ 1024MB
"ik _heb_ niets tegen Microsoft, ik heb iets tegen
de uitwassen *van* Microsoft"
.



Relevant Pages

  • Re: Plz help..SocketServer UDP server losing lots of packets
    ... API's within python. ... logfile = open ... from socket import * ... This is horrible code:/ ...
    (comp.lang.python)
  • tips requested for a log-processing script
    ... As a relatively new user of Python I would like to ask your advice on the following script I want to create. ... Each record is identified by a date and a itemID. ... All records in the logfile with other itemID's can be ignored. ... when I load the logfile in a spreadsheet I can create a pivot table which does about the same;-] but that is not what I want; the processing must be automated in the end with a periodic script which e-mails the summary of the keyfigure every month. ...
    (comp.lang.python)
  • Re: Watch log
    ... I need to write an application with python that will read this file. ... Have your program log to a socket and have the ... have the latest log entries in the monitor program. ... of the logfile. ...
    (comp.lang.python)
  • Re: Multiple files editing
    ... echo out of something>> logfile ... you have a few more options with a real shell. ... Never take for granted that the script is run from the current directory ...
    (alt.os.linux)
  • Re: python and php prblem with apache
    ... How is python started by your cgi script. ... Yess I have the correct she-bang line, I even try both of them and the ... echo Content-Type: text/plain ...
    (alt.os.linux.suse)