Convert AWK regex to Python

J jnr.gonzalez at googlemail.com
Tue May 17 06:07:34 EDT 2011


Hello,

I have managed to get my script finished in the end by taking bits from everyone who answered.  Thank you so much.  the finished query string looks like this (still not the best but it gets the job done.  Once I learn to code more with Python I will probably go back to it and re-write it):-

# Log file to work on
filetoread = open("/tmp/pdu.log", "r")
# Perform filtering in the log file
text = filetoread.read()
text = text.replace("<G_", "")
text = text.replace(".", " ")
text = text.replace(r"(", " ")
filetoread.close()
# File to write output to
filetowrite = file("/tmp/pdu_filtered.log", "w")
# Write new log file
filetowrite.write(text)
filetowrite.close()
# Read new log and get required fields from it
filtered_log =  open("/tmp/pdu_filtered.log", "r")
filtered_line = filtered_log.readlines()
for line in filtered_line:
	field = line.split(" ")
	field5 = field[5].rsplit("_", 1)
	print field5[0], field[14], field[22]
print "Done"



More information about the Python-list mailing list