I'm scanning log files (in a directory) for specific lines, need to output all in a text file.
For some reason, I do not understand, I have an error:
NameError: name 's' is not defined
I tried to assign Var s
to a different Var but still cannot get around the problem.
In my code, I going to have one "if" and 5 "elif" like this:
If
var1
elif
var2
elif
var3
elif
var4
elif
var5
elif
var6
write.output_file(var1+var2+var3+var4+var5+var6+'\n')
Here is the code:
import os
import re
start_tm = '," Start Time'
test_ID = ' Host Name: '
cell_f = open('C:\\03\\OUTCOME.txt','w')
given_path = 'C:\\02\\en15\\TST2'
for filename in os.listdir(given_path):
filepath = os.path.join(given_path, filename)
if os.path.isfile(filepath):
#print("File Name: ", filename)
print("File Name\\Path:", filepath+'\n')
with open(filepath) as mfile:
for rn_l in mfile:
rn_l= rn_l.rstrip()
if start_tm in rn_l:
*extraWords,st_t1 = rn_l.split('Time') # Grtting Start Time #
s=str(st_t1)
s=s.replace('"','')
print ("Start String \"s\"is a TYPE ", type(s))
print ("START TIME STRING "+s)
elif test_ID in rn_l:
*extraWords,t_id1,t_id2, = rn_l.split( )
print ("TESTER ID --->>> "+t_id1)
t_id11,t_id12, = rn_l.split('Host')
*w,e,c,d = re.split(" +", t_id11)
cell = str(e+'_'+c)
cell = cell.replace('[','').replace(']','')
print ("Cell Line " + cell+'\n')