Re: get quote enclosed field in a line
- From: Paul McGuire <ptmcg@xxxxxxxxxxxxx>
- Date: Thu, 17 Apr 2008 19:39:12 -0700 (PDT)
On Apr 17, 6:50 pm, John Machin <sjmac...@xxxxxxxxxxx> wrote:
xah...@xxxxxxxxx wrote:
is there a simple way in perl, python, or awk/shell/pipe, that gets
the user agent field in a apache log?
e.g. the typical line is like this:
189.139.109.235 - - [07/Apr/2008:00:00:16 -0400] "GET /
Periodic_dosage_dir/lacru/manara.html HTTP/1.1" 200 1933 xahlee.org
"http://xahlee.org/Periodic_dosage_dir/lacru/manara2.html" "Mozilla/
5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.13) Gecko/20080311
Firefox/2.0.0.13" "-"
I want the part: "Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:
1.8.1.13) Gecko/20080311 Firefox/2.0.0.13".
C:\junk>type xah.py
import cStringIO, csv, pprint
line = '''189.139.109.235 - etc etc etc'''
f = cStringIO.StringIO(line)
reader = csv.reader(f, delimiter=" ")
row = reader.next()
pprint.pprint(row)
C:\junk>xah.py
['189.139.109.235',
'-',
'-',
'[07/Apr/2008:00:00:16',
'-0400]',
'GET / Periodic_dosage_dir/lacru/manara.html HTTP/1.1',
'200',
'1933',
'xahlee.org',
'http://xahlee.org/Periodic_dosage_dir/lacru/manara2.html',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.13)
Gecko/20080311 Fi
refox/2.0.0.13',
'-']
If you don't like that, just hang about -- there's sure to be a
pyparsing bus coming by real soon now :-)
Cheers,
John
Beep, beep!
You can find a pyparsing-based log server file parser at
http://pyparsing.wikispaces.com/space/showimage/httpServerLogParser.py.
Vrooom!
-- Paul
.
- References:
- Re: get quote enclosed field in a line
- From: John Machin
- Re: get quote enclosed field in a line
- Prev by Date: Database vs Data Structure?
- Next by Date: Re: get quote enclosed field in a line
- Previous by thread: Re: get quote enclosed field in a line
- Next by thread: Re: get quote enclosed field in a line
- Index(es):