I am extacting the output based on the if else elif
condition and printing the line starting with pattren | SUCCESS |
, however i'm trying to add the underline marks for | SUCCESS |
line just to make distinction.
As i'm using a variable UNDERLINE
for making that underline
, Just curious to Know if there is better way to give that underline
.
UNDERLINE = '---------------------------------------------'
def Filter_Suc():
patt_success = False
with open("shanghai2_out") as f:
for line in f:
if patt_success:
if "FAILED" in line or "UNREACHABLE" in line:
patt_success = False
else:
if "| SUCCESS |" in line:
print(UNDERLINE)
print(line.rstrip('\n'))
print(UNDERLINE)
else:
print(line.rstrip('\n'))
elif "| SUCCESS |" in line:
print(line.rstrip('\n'))
patt_success = True
Filter_Suc()
The above code works well and producing the below output:
However, the output between the underline
is okay but as i needed only the Hostname ie that is udalt-chef.preet.com
SO, just wondering how we can chop off the | SUCCESS | rc=0 >>
---------------------------------------------------------
udalt-chef.preet.com | SUCCESS | rc=0 >>
---------------------------------------------------------
domain odence.com
search odence.com global.odence.com
nameserver 192.168.2.14
nameserver 192.168.2.15
Sorry for asking too much! However, will appreciate any help in intrim.