15 May 17:21
(no subject)
From: root <jatinder.singh2 <at> wipro.com>
Subject: (no subject)
Newsgroups: gmane.comp.python.tutor
Date: 2008-05-15 15:22:22 GMT
Subject: (no subject)
Newsgroups: gmane.comp.python.tutor
Date: 2008-05-15 15:22:22 GMT
hi ,i am working to replace three lines in a httpd.conf file using
regular expression.i am able to change only one among them but while
replacing other i am not geeting good idea to replace all the three
lines just in a single script ,,my script is like
#!usr/bin/python
import sys
import os
import re
import string
def replace_file(file,search,replace):
cregex=re.compile(search)
for current_line in file:
if cregex.search(current_line):
current_line=re.sub(search,replace,current_line)
print current_line
else:
print current_line
def main():
file =open("/root/Desktop/httpd.conf").readlines()
replace_file(file,'User apache ' , 'User myuser ')
#replace_file(file,'Group apache','Group myuser')
#replace_file(file,DirectoryIndex\ index.html\ index.html.var,DirectoryIndex\ index.html\
index.html.var\ login.html)
(Continue reading)
RSS Feed