Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5557

Re: Convert AWK regex to Python

Newsgroups comp.lang.python
Date 2011-05-17 03:07 -0700
Subject Re: Convert AWK regex to Python
From J <jnr.gonzalez@googlemail.com>
Message-ID <mailman.1664.1305626865.9059.python-list@python.org> (permalink)

Show all headers | View raw


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"

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Convert AWK regex to Python J <jnr.gonzalez@googlemail.com> - 2011-05-17 03:07 -0700
  Re: Convert AWK regex to Python AlienBaby <matt.j.warren@gmail.com> - 2011-05-17 06:33 -0700

csiph-web