Hello all,
I'm writing a python script that searches standard parameter info from a config file so that it can find unique info to the right of the parameter. For instance here is my list:
Code:
SID 2861
RID 383
hostname server1
hostaddress server1.domain.com
ifcfg-eth0 192.168.2.100
eth0-netmask 255.255.255.0
gateway 192.168.2.1
ifcfg-eth1 192.168.1.100
eth1-netmask 255.255.255.0
lanes 6 1 2 3 4 5 31
xterminal no
macs yes
The first column is always the same per server and the second column changes.
I have found a way to match the line and print the info on the second column:
Code:
for line in open("ss2861.cfg"):
if "SID" in line:
SID = line[4:8]
print SID
But this is a bad solution, because a lot of the parameters in the second column vary in length so it's not a good solution to just count how many characters are after the first parameter.
I've been trying to find a way to search the first parameter AND print the second column. So far I've only been able to find one or the other.
This split works, but now I have the whole second columns without having searched for the specific parameter:
Code:
with open('ss2861.cfg') as inf:
for line in inf:
parts = line.split()
if len(parts) > 1:
print parts[1]
I'm new to python and I know bash would be able to handle this with awk, but I'm trying to force myself to do this with python so I can learn another scripting tool.
If anyone can assist I'd be very grateful. If this is not enough info then please let me know. Thank you! Keith