Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > get quote enclosed field in a line

Reply
Thread Tools

get quote enclosed field in a line

 
 
xahlee@gmail.com
Guest
Posts: n/a
 
      04-17-2008
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

http://xahlee.org/


 
Reply With Quote
 
 
 
 
Martin P. Hellwig
Guest
Posts: n/a
 
      04-17-2008
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
>
> ∑ http://xahlee.org/
>
> ☄


Something like:
# cut -d '"' -f 6 < httpd-access.log
?
--
mph
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      04-17-2008
"" <> wrote in news:c4c50034-2f90-42ce-82ca-:

[ 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 <>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
Reply With Quote
 
Skye Shaw!@#$
Guest
Posts: n/a
 
      04-18-2008
> xah...@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

 
Reply With Quote
 
Michael Tosch
Guest
Posts: n/a
 
      04-18-2008
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
>
> ∑ http://xahlee.org/
>
> ☄


awk -F\" '{print $6}' httpd-access.log
awk -F\" 'NF>6{print $6}' httpd-access.log

--
Michael Tosch @ hp : com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quote-Dot-Quote Operator kvnsmnsn@hotmail.com C++ 6 06-14-2008 11:34 PM
get quote enclosed field in a line xahlee@gmail.com Python 7 04-18-2008 05:17 PM
Datagrid on load; replace all double single quote to single quote to display to user Eric Layman ASP .Net 3 04-14-2007 07:16 AM
replacing strange quote with standard quote Stimp ASP .Net 2 09-20-2006 10:01 AM
Single Quote Versus Double Quote In A href link knee-dragger@hotmail.com HTML 3 06-13-2006 12:42 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57