Re: Multiple files editing
- From: "Theo v. Werkhoven" <theo@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Aug 2007 00:29:01 +0200
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"
.
- References:
- Multiple files editing
- From: GT
- Multiple files editing
- Prev by Date: Re: Linspire is the easiest Linux :-(
- Next by Date: Re: Linspire is the easiest Linux :-(
- Previous by thread: Multiple files editing
- Next by thread: Any Insider Knowledge when CNR will be ready for Linspire, and the other distro's?
- Index(es):
Relevant Pages
|