|
Prev: FAQ 9.19 How do I return the user's mail address?
Next: FAQ 9.25 How do I fetch/put an FTP file?
From: xahlee on 17 Apr 2008 19:06 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". Thanks. Xah xah(a)xahlee.org â http://xahlee.org/ â
From: Martin P. Hellwig on 17 Apr 2008 19:21 xahlee(a)gmail.com 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". > > Thanks. > > Xah > xah(a)xahlee.org > ∑ http://xahlee.org/ > > ☄ Something like: # cut -d '"' -f 6 < httpd-access.log ? -- mph
From: A. Sinan Unur on 17 Apr 2008 19:39 "xahlee(a)gmail.com" <xahlee(a)gmail.com> wrote in news:c4c50034-2f90-42ce-82ca-8ba214d49ec9(a)d1g2000hsg.googlegroups.com: [ Replying only in clpm because I can only talk about Perl ] > is there a simple way in perl s/perl/Perl ;-) > 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". Simple. #!/usr/bin/perl use strict; use warnings; my $line = <<EOL; 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" "-" EOL # deal with any extra spacing and/or # line breaks inserted in posting $line =~ s/^\s+//; $line =~ s/\s+$//; $line =~ s/\s+/ /g; if ( $line =~ /"([^"]+)" "[^"]+"\z/ ) { print "User agent: $1\n"; } __END__ C:\Temp> lp User agent: Mozilla/ 5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13 Sinan -- A. Sinan Unur <1usa(a)llenroc.ude.invalid> (remove .invalid and reverse each component for email address) comp.lang.perl.misc guidelines on the WWW: http://www.rehabitation.com/clpmisc/
From: Skye Shaw! on 18 Apr 2008 02:35 > xah...(a)gmail.com wrote: > > is there a simple way in perl, python, or awk/shell/pipe, that gets > > the user agent field in a apache log? > Something like: > # cut -d '"' -f 6 < httpd-access.log > ? > -- > mph Doesn't it feel like autosplit mode never gets any run time? perl -laF'"' -ne'print $F[5]' access_log
From: Michael Tosch on 18 Apr 2008 13:17 xahlee(a)gmail.com 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". > > Thanks. > > Xah > xah(a)xahlee.org > ∑ http://xahlee.org/ > > ☄ awk -F\" '{print $6}' httpd-access.log awk -F\" 'NF>6{print $6}' httpd-access.log -- Michael Tosch @ hp : com
|
Pages: 1 Prev: FAQ 9.19 How do I return the user's mail address? Next: FAQ 9.25 How do I fetch/put an FTP file? |