[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Parsing an apache access log line

Joe Nciri

7/16/2007 11:59:00 AM

a have a line to parse....

10.88.90.75 - - [16/Jul/2007:07:46:09 -0400] "GET /star/images/main.gif
HTTP/1.1" 200 334


anyone has a better idea... got stuck coming up with one simple regex (
the double quote...) Need to tokenize the line,

token 1 = 10.88.90.75
token 2 = -
token 3 = -
token 4 = [16/Jul/2007:07:46:09 -0400]
token 5 = "GET /star/images/main.gif HTTP/1.1"
token 6 = 200
token 7 = 234


can some one help please.

Joe.

--
Posted via http://www.ruby-....

11 Answers

Robert Klemme

7/16/2007 12:06:00 PM

0

2007/7/16, Joe Nciri <dev@logixcel.com>:
> a have a line to parse....
>
> 10.88.90.75 - - [16/Jul/2007:07:46:09 -0400] "GET /star/images/main.gif
> HTTP/1.1" 200 334
>
>
> anyone has a better idea... got stuck coming up with one simple regex (
> the double quote...) Need to tokenize the line,
>
> token 1 = 10.88.90.75
> token 2 = -
> token 3 = -
> token 4 = [16/Jul/2007:07:46:09 -0400]
> token 5 = "GET /star/images/main.gif HTTP/1.1"
> token 6 = 200
> token 7 = 234
>
>
> can some one help please.

Try this as a starting point:

line.scan %r{
\S+
| \[[^\]]*\]
| "[^"]*"
}x

(untested)

Kind regards

robert

Jens Wille

7/16/2007 12:08:00 PM

0

hi joe!

Joe Nciri [2007-07-16 13:59]:
> a have a line to parse....
>
> 10.88.90.75 - - [16/Jul/2007:07:46:09 -0400] "GET /star/images/main.gif
> HTTP/1.1" 200 334
maybe you want to have a look at log_parser:
<http://topfunky.net/svn/plugins/mint/lib/log_par...

cheers
jens

--
Jens Wille, Dipl.-Bibl. (FH)
prometheus - Das verteilte digitale Bildarchiv für Forschung & Lehre
Kunsthistorisches Institut der Universität zu Köln
Albertus-Magnus-Platz, D-50923 Köln
Tel.: +49 (0)221 470-6668, E-Mail: jens.wille@uni-koeln.de
http://www.prometheus-bild...

SonOfLilit

7/16/2007 12:10:00 PM

0

/([0-9.]*) (-) (-) (\[.*\]) (\".*\") ([0-9]*) ([0-9]*)/ comes to mind,
although I'm probably wrong with the backslashes - some of the things
I escaped probably aren't significant characters and some other ones
probably are.

Could you provide a test suite with more lines?

Hey, wouldn't /(?^| )[^\S]*|\".*\")(?| )/, work to find each of the
tokens (that is, iterate it to find ALL matches)?


Aur

On 7/16/07, Joe Nciri <dev@logixcel.com> wrote:
> a have a line to parse....
>
> 10.88.90.75 - - [16/Jul/2007:07:46:09 -0400] "GET /star/images/main.gif
> HTTP/1.1" 200 334
>
>
> anyone has a better idea... got stuck coming up with one simple regex (
> the double quote...) Need to tokenize the line,
>
> token 1 = 10.88.90.75
> token 2 = -
> token 3 = -
> token 4 = [16/Jul/2007:07:46:09 -0400]
> token 5 = "GET /star/images/main.gif HTTP/1.1"
> token 6 = 200
> token 7 = 234
>
>
> can some one help please.
>
> Joe.
>
> --
> Posted via http://www.ruby-....
>
>

Robert Klemme

7/16/2007 12:49:00 PM

0

2007/7/16, Robert Klemme <shortcutter@googlemail.com>:
> 2007/7/16, Joe Nciri <dev@logixcel.com>:
> > a have a line to parse....
> >
> > 10.88.90.75 - - [16/Jul/2007:07:46:09 -0400] "GET /star/images/main.gif
> > HTTP/1.1" 200 334
> >
> >
> > anyone has a better idea... got stuck coming up with one simple regex (
> > the double quote...) Need to tokenize the line,
> >
> > token 1 = 10.88.90.75
> > token 2 = -
> > token 3 = -
> > token 4 = [16/Jul/2007:07:46:09 -0400]
> > token 5 = "GET /star/images/main.gif HTTP/1.1"
> > token 6 = 200
> > token 7 = 234
> >
> >
> > can some one help please.
>
> Try this as a starting point:
>
> line.scan %r{
> \S+
> | \[[^\]]*\]
> | "[^"]*"
> }x
>
> (untested)

I think I got the order wrong. Rather do

line.scan %r{
\[[^\]]*\]
| "[^"]*"
| \S+
}x

Or do an explicit parse like the one Aur suggested.

Kind regards

robert

Phil Meier

7/16/2007 2:27:00 PM

0

Joe Nciri schrieb:
> a have a line to parse....
>
> 10.88.90.75 - - [16/Jul/2007:07:46:09 -0400] "GET /star/images/main.gif
> HTTP/1.1" 200 334
>
>
> anyone has a better idea... got stuck coming up with one simple regex (
> the double quote...) Need to tokenize the line,
>
> token 1 = 10.88.90.75
> token 2 = -
> token 3 = -
> token 4 = [16/Jul/2007:07:46:09 -0400]
> token 5 = "GET /star/images/main.gif HTTP/1.1"
> token 6 = 200
> token 7 = 234
>
>
> can some one help please.
>
> Joe.
>

line = "10.88.90.75 - - [16/Jul/2007:07:46:09 -0400] \"GET
star/images/main.gif HTTP/1.1\" 200 334"
token =
/^(.*?)\s+(.*?)\s+(.*?)\s+(\[.*?\])\s+(\".*?\")\s+(\d+)\s+(\d+)$/.match(line)

=> token[1] = 10.88.90.75
token[2] = -
token[3] = -
etc.

BR Phil

Terry Cross

9/14/2010 2:34:00 PM

0

On Sep 14, 5:19 am, Zev <zev_h...@yahoo.com> wrote:
> On Sep 14, 11:14 am, Terry Cross <tcros...@hotmail.com> wrote:
>
> > On Sep 13, 10:42 am, Emma <e...@newsguy.com> wrote:
> > The US and Israel have killed more Muslims by a factor of 100 to one.
>
> I've read that over the centuries,
> Muslims have killed tens of millions of Hindus.
> Can you show us how you arrived at that factor?

Not only do you want an abrupt change of subject, you want me to prove
your numbers? Why can't you deal with the fact I gave you?

From information from the Israel Ministry of Foreign Affairs, we can
calculate that as of April 2006 there have been 4,758 terrorism deaths
in Israel since 1920 and 2,178 since the occupation of the West Bank
and Gaza (the Occupied Palestinian Territories) and the Golan Heights
(Syria) in 1967.
http://globalavoidablemortality.blogspot.com/2006/05/post-1967-palestinian-israeli-d...

In contrast, the number of Palestinians killed is close to 2,000,000.
http://answers.yahoo.com/question/index?qid=20070910103...

See also http://sites.google.com/site/falastinel7ora/if-only-amer...

http://domino.un.org/UNISPAL.NSF/0/be07c80cda4579468525734800500272?Op...

Iraqi Civilians Killed, Estimated - A UN issued report dated Sept 20,
2006 stating that Iraqi civilian casualties have been significantly
under-reported. Casualties are reported at 50,000 to over 100,000, but
may be much higher. Some informed estimates place Iraqi civilian
casualities at over 600,000.

In contrast, 4,420 US soldiers killed, 31,926 seriously wounded.
http://usliberals.about.com/od/homelandsecurit1/a/IraqN...

TCross

Zev

9/14/2010 4:15:00 PM

0

On Sep 14, 4:34 pm, Terry Cross <tcros...@hotmail.com> wrote:
> On Sep 14, 5:19 am, Zev <zev_h...@yahoo.com> wrote:
> > On Sep 14, 11:14 am, Terry Cross <tcros...@hotmail.com> wrote:
> > > On Sep 13, 10:42 am, Emma <e...@newsguy.com> wrote:
> > > The US and Israel have killed more Muslims by a factor of 100 to one.

> > I've read that over the centuries,
> > Muslims have killed tens of millions of Hindus.
> > Can you show us how you arrived at that factor?
>
> Not only do you want an abrupt change of subject, you want me to prove
> your numbers?  Why can't you deal with the fact I gave you?

Oops, I missed the exact point you were making.
Sorry.

> From information  from the Israel Ministry of Foreign Affairs, we can
> calculate that as of April 2006 there have been 4,758 terrorism deaths
> in Israel since 1920 and 2,178 since the occupation of the West Bank
> and Gaza (the Occupied Palestinian Territories) and the Golan Heights
> (Syria) in 1967.http://globalavoidablemortality.blogspot.com/2006/05/post-1......
>
> In contrast, the number of Palestinians killed is close to 2,000,000.
http://answers.yahoo.com/question/index?qid=20070910103...

Two Million???!!!
Terry, do you actually believe that?
Bear in mind the number of Arab Palestinians in 1948 and today.
It's absurd, no one even claims that many,
except for the person who "answered" the question.

> See alsohttp://sites.google.com/site/falastinel7ora/if-only-amer...
>
> http://domino.un.org/UNISPAL.NSF/0/be07c80cda45794685257348......
>
> Iraqi Civilians Killed, Estimated - A UN issued report dated Sept 20,
> 2006 stating that Iraqi civilian casualties have been significantly
> under-reported. Casualties are reported at 50,000 to over 100,000, but
> may be much higher. Some informed estimates place Iraqi civilian
> casualities at over 600,000.

> In contrast, 4,420 US soldiers killed, 31,926 seriously wounded.

http://usliberals.about.com/od/homelandsecurit1/a/IraqN...

Does that count soldiers, fighting in the U.S. army,
who hadn't yet received American citizenship?
Does it count WTC deaths?
If not, why not?
Does it count "Muslim on Muslim" violence in Iraq?
If yes, why?

drahcir

9/14/2010 4:33:00 PM

0

On Tue, 14 Sep 2010 07:34:10 -0700 (PDT), Terry Cross
<tcross77@hotmail.com> wrote:

>On Sep 14, 5:19?am, Zev <zev_h...@yahoo.com> wrote:
>> On Sep 14, 11:14?am, Terry Cross <tcros...@hotmail.com> wrote:
>>
>> > On Sep 13, 10:42?am, Emma <e...@newsguy.com> wrote:
>> > The US and Israel have killed more Muslims by a factor of 100 to one.
>>
>> I've read that over the centuries,
>> Muslims have killed tens of millions of Hindus.
>> Can you show us how you arrived at that factor?
>
>Not only do you want an abrupt change of subject, you want me to prove
>your numbers? Why can't you deal with the fact I gave you?
>
>From information from the Israel Ministry of Foreign Affairs, we can
>calculate that as of April 2006 there have been 4,758 terrorism deaths
>in Israel since 1920 and 2,178 since the occupation of the West Bank
>and Gaza (the Occupied Palestinian Territories) and the Golan Heights
>(Syria) in 1967.
>http://globalavoidablemortality.blogspot.com/2006/05/post-1967-palestinian-israeli-d...
>
>In contrast, the number of Palestinians killed is close to 2,000,000.
>http://answers.yahoo.com/question/index?qid=20070910103...

LOL! Thank you for giving concrete evidence to the group that you are
a nut. Who but a nut would supply a 4 word pronouncement from some
anonymous idiot on Yahoo Answers as evidence of ANYTHING??? Terry, you
grossly overestimate not only your intelligence, but your sanity as
well.

And here's something else, fruitcake. There were about 8 million
germans killed in WWII, and about 400,000 americans. Casualties do not
imply who the bad guy is.
>
>See also http://sites.google.com/site/falastinel7ora/if-only-amer...
>
>http://domino.un.org/UNISPAL.NSF/0/be07c80cda4579468525734800500272?Op...
>
>Iraqi Civilians Killed, Estimated - A UN issued report dated Sept 20,
>2006 stating that Iraqi civilian casualties have been significantly
>under-reported. Casualties are reported at 50,000 to over 100,000, but
>may be much higher. Some informed estimates place Iraqi civilian
>casualities at over 600,000.
>
>In contrast, 4,420 US soldiers killed, 31,926 seriously wounded.
>http://usliberals.about.com/od/homelandsecurit1/a/IraqN...
>
>TCross

drahcir

9/14/2010 4:46:00 PM

0

On Tue, 14 Sep 2010 07:34:10 -0700 (PDT), Terry Cross
<tcross77@hotmail.com> wrote:

>On Sep 14, 5:19?am, Zev <zev_h...@yahoo.com> wrote:
>> On Sep 14, 11:14?am, Terry Cross <tcros...@hotmail.com> wrote:
>>
>> > On Sep 13, 10:42?am, Emma <e...@newsguy.com> wrote:
>> > The US and Israel have killed more Muslims by a factor of 100 to one.
>>
>> I've read that over the centuries,
>> Muslims have killed tens of millions of Hindus.
>> Can you show us how you arrived at that factor?
>
>Not only do you want an abrupt change of subject, you want me to prove
>your numbers? Why can't you deal with the fact I gave you?
>
>From information from the Israel Ministry of Foreign Affairs, we can
>calculate that as of April 2006 there have been 4,758 terrorism deaths
>in Israel since 1920 and 2,178 since the occupation of the West Bank
>and Gaza (the Occupied Palestinian Territories) and the Golan Heights
>(Syria) in 1967.
>http://globalavoidablemortality.blogspot.com/2006/05/post-1967-palestinian-israeli-d...
>
>In contrast, the number of Palestinians killed is close to 2,000,000.
>http://answers.yahoo.com/question/index?qid=20070910103...
>
>See also http://sites.google.com/site/falastinel7ora/if-only-amer...
>
>http://domino.un.org/UNISPAL.NSF/0/be07c80cda4579468525734800500272?Op...

OK, fruitcake, this is gonna cost you. You need to demonstrate
PRECISELY where in your above un.org cite, there is any mention or
implication of 2 million palestinian arabs killed. If you don't do it,
it will be crystal clear that you are a liar as well as a nut.
>
>Iraqi Civilians Killed, Estimated - A UN issued report dated Sept 20,
>2006 stating that Iraqi civilian casualties have been significantly
>under-reported. Casualties are reported at 50,000 to over 100,000, but
>may be much higher. Some informed estimates place Iraqi civilian
>casualities at over 600,000.
>
>In contrast, 4,420 US soldiers killed, 31,926 seriously wounded.
>http://usliberals.about.com/od/homelandsecurit1/a/IraqN...
>
>TCross

drahcir

9/14/2010 4:49:00 PM

0

On Tue, 14 Sep 2010 09:14:51 -0700 (PDT), Zev <zev_horn@yahoo.com>
wrote:

>On Sep 14, 4:34 pm, Terry Cross <tcros...@hotmail.com> wrote:
>> On Sep 14, 5:19 am, Zev <zev_h...@yahoo.com> wrote:
>> > On Sep 14, 11:14 am, Terry Cross <tcros...@hotmail.com> wrote:
>> > > On Sep 13, 10:42 am, Emma <e...@newsguy.com> wrote:
>> > > The US and Israel have killed more Muslims by a factor of 100 to one.
>
>> > I've read that over the centuries,
>> > Muslims have killed tens of millions of Hindus.
>> > Can you show us how you arrived at that factor?
>>
>> Not only do you want an abrupt change of subject, you want me to prove
>> your numbers?  Why can't you deal with the fact I gave you?
>
>Oops, I missed the exact point you were making.
>Sorry.
>
>> From information  from the Israel Ministry of Foreign Affairs, we can
>> calculate that as of April 2006 there have been 4,758 terrorism deaths
>> in Israel since 1920 and 2,178 since the occupation of the West Bank
>> and Gaza (the Occupied Palestinian Territories) and the Golan Heights
>> (Syria) in 1967.http://globalavoidablemortality.blogspot.com/2006/05/post-1......
>>
>> In contrast, the number of Palestinians killed is close to 2,000,000.
>http://answers.yahoo.com/question/index?qid=20070910103...
>
>Two Million???!!!
>Terry, do you actually believe that?
>Bear in mind the number of Arab Palestinians in 1948 and today.
>It's absurd, no one even claims that many,
>except for the person who "answered" the question.

She was drooling so much she forgot to think before pushing "send".
>
>> See alsohttp://sites.google.com/site/falastinel7ora/if-only-amer...
>>
>> http://domino.un.org/UNISPAL.NSF/0/be07c80cda45794685257348......
>>
>> Iraqi Civilians Killed, Estimated - A UN issued report dated Sept 20,
>> 2006 stating that Iraqi civilian casualties have been significantly
>> under-reported. Casualties are reported at 50,000 to over 100,000, but
>> may be much higher. Some informed estimates place Iraqi civilian
>> casualities at over 600,000.
>
>> In contrast, 4,420 US soldiers killed, 31,926 seriously wounded.
>
>http://usliberals.about.com/od/homelandsecurit1/a/IraqN...
>
>Does that count soldiers, fighting in the U.S. army,
>who hadn't yet received American citizenship?
>Does it count WTC deaths?
>If not, why not?
>Does it count "Muslim on Muslim" violence in Iraq?
>If yes, why?