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)
if __name__ == '__main__':
main()
I am running this command to save the output in a temp file then replacing with
original httpd.conf.
can I do this in a single python script that'll change three lines and
there should not any need to replace it.that is the change should
directly save to the source file......??????????
any help will be appreciated.Thanks
Please do not print this email unless it is absolutely necessary.
The information contained in this electronic message and any attachments to
this message are intended for the exclusive use of the addressee(s) and may
contain proprietary, confidential or privileged information. If you are not the
intended recipient, you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately and destroy all copies of this message and
any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should
check this email and any attachments for the presence of viruses. The company
accepts no liability for any damage caused by any virus transmitted by this
email.
www.wipro.com
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor