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


Groups > comp.lang.python > #5511

Re: Convert AWK regex to Python

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.060
X-Spam-Evidence '*H*': 0.88; '*S*': 0.00; 'subject:Python': 0.04; '(same': 0.07; 'awk': 0.16; 'example).': 0.16; 'peter,': 0.16; 'previously,': 0.16; 'subject:Convert': 0.16; 'subject:regex': 0.16; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'header:In- Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'file,': 0.22; 'filter': 0.22; 'individually': 0.23; 'received:209.85.213': 0.23; 'example': 0.24; 'skip:[ 10': 0.26; 'id:': 0.27; 'string': 0.29; 'from:addr:googlemail.com': 0.29; 'cc:addr:python.org': 0.31; 'selecting': 0.31; 'separated': 0.31; 'break': 0.33; 'several': 0.33; '(for': 0.33; 'lines': 0.34; 'file.': 0.34; 'file': 0.35; 'couple': 0.35; 'header:User-Agent:1': 0.35; 'processing': 0.37; 'received:209.85': 0.37; 'received:google.com': 0.38; 'current': 0.38; 'log': 0.38; 'lets': 0.39; 'received:209': 0.39; 'except': 0.39; 'similar': 0.40; 'essence': 0.68; 'to:addr:googlegroups.com': 0.69; 'thousands': 0.69; 'evaluate': 0.72; 'reply-to:no real name:2**0': 0.72; 'header:Reply-To:1': 0.72; 'spaces': 0.73; 'fields).': 0.84; 'skip:c 90': 0.84; 'reply- to:addr:googlegroups.com': 0.93
Newsgroups comp.lang.python
Date Mon, 16 May 2011 03:57:49 -0700 (PDT)
In-Reply-To <mailman.1639.1305540395.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.1640.1305543472.9059.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 82.94.164.166
X-Trace 1305543472 news.xs4all.nl 32470 [::ffff:82.94.164.166]:60157
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5511

Show key headers only | View raw


Hello Peter, Angelico,

Ok lets see, My aim is to filter out several fields from a log file and write them to a new log file.  The current log file, as I mentioned previously, has thousands of lines like this:-
2011-05-16 09:46:22,361 [Thread-4847133] PDU D <G_CC_SMS_SERVICE_51408_656.O_ CC_SMS_SERVICE_51408_656-ServerThread-VASPSessionThread-7ee35fb0-7e87-11e0-a2da-00238bce423b-TRX - 2011-05-16 09:46:22 - OUT - (submit_resp: (pdu: L: 53 ID: 80000004 Status: 0 SN: 25866) 98053090-7f90-11e0-a2da-00238bce423b (opt: ) ) >

All the lines in the log file are similar and they all have the same length (same amount of fields).  Most of the fields are separated by spaces except for couple of them which I am processing with AWK (removing "<G_" from the string for example).  So in essence what I want to do is evaluate each line in the log file and break them down into fields which I can call individually and write them to a new log file (for example selecting only fields 1, 2 and 3).

I hope this is clearer now

Regards,

Junior

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


Thread

Re: Convert AWK regex to Python J <jnr.gonzalez@googlemail.com> - 2011-05-16 03:57 -0700

csiph-web