The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 05-27-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,540
if you have Python
Code:
#!/usr/bin/env python
import fileinput
d={ "Server":"0.0.0.0", "ServerPort":"1", "Enable Server":"0" }
for line in fileinput.FileInput("file",inplace=1):
    line=line.strip()
    if not line.startswith("#") and line!="":
        line=line.split("=")        
        print line[0]+"="+d[line[0]]
    else:
        print line
output
Code:
# ./test.py
# more file
### Welcome to server ###
### Server address and port ###

Server=0.0.0.0
### Replace Server=0.0.0.0 ###

ServerPort=1
### Replace ServerPort=1 ####
### Enable Server ##

Enable Server=0

### Replace Enable Server=0 ###
### END OF FILE ##