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


Groups > comp.lang.python > #5557

Re: Convert AWK regex to Python

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <jnr.gonzalez@googlemail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.038
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'subject:Python': 0.04; 'bits': 0.07; 'python': 0.07; '"done"': 0.09; 'output': 0.12; '"r")': 0.16; '"w")': 0.16; 'answered.': 0.16; 'subject:Convert': 0.16; 'subject:regex': 0.16; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'script': 0.26; 'looks': 0.28; 'string': 0.29; 'from:addr:googlemail.com': 0.29; 'query': 0.29; 'probably': 0.30; 'cc:addr:python.org': 0.31; 'filtering': 0.31; 'thank': 0.32; 'file': 0.35; 'done.': 0.35; 'print': 0.35; 'header :User-Agent:1': 0.35; 'hello,': 0.36; 'skip:o 20': 0.37; 'received:google.com': 0.38; 'but': 0.38; 'log': 0.38; 'much.': 0.39; 'end': 0.39; 'finished': 0.40; 'learn': 0.60; 'best': 0.60; 'taking': 0.61; 'back': 0.61; 'received:74.125.83': 0.69; 'to:addr:googlegroups.com': 0.69; 'reply-to:no real name:2**0': 0.72; 'header:Reply-To:1': 0.72; 'received:74.125.83.56': 0.84; 'received:mail-gw0-f56.google.com': 0.84; 'reply- to:addr:googlegroups.com': 0.93
Newsgroups comp.lang.python
Date Tue, 17 May 2011 03:07:34 -0700 (PDT)
In-Reply-To <mailman.1646.1305563954.9059.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=195.233.250.6; posting-account=cLrwyAoAAAB9UeiSeYmBPmVn0SNqa__5
User-Agent G2/1.0
MIME-Version 1.0
Subject Re: Convert AWK regex to Python
From J <jnr.gonzalez@googlemail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To comp.lang.python@googlegroups.com
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.1664.1305626865.9059.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 82.94.164.166
X-Trace 1305626865 news.xs4all.nl 49181 [::ffff:82.94.164.166]:51757
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5557

Show key headers only | 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