PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.info.servers.unix > parsing log files
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.info.servers.unix Web servers for UNIX platforms.

parsing log files

Réponse
 
LinkBack Outils de la discussion
Vieux 07/06/2006, 05h24   #1
yawnmoth
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut parsing log files

Is there a way to make every IP address in a log file appear only once
and have, beside that IP address, the number of times that that IP
address appeared in the unparsed log file?

eg. if 127.0.0.1 appears in a log file 30 times, is there a way to make
a file that says something like...

127.0.0.1: 30

It's an easy enough task to do with a script, but I'm currious if it
can be done with command line tools, instead.

  Réponse avec citation
Vieux 07/06/2006, 09h35   #2
Chris Davies
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: parsing log files

yawnmoth <terra1024@yahoo.com> wrote:
> Is there a way to make every IP address in a log file appear only once
> and have, beside that IP address, the number of times that that IP
> address appeared in the unparsed log file?


What do a few lines of the log file look like?


> eg. if 127.0.0.1 appears in a log file 30 times, is there a way to make
> a file that says something like...


> 127.0.0.1: 30


awk, sort and uniq sound like candidates for this, but without seeing
the log file it's tricky to offer a solution.


> It's an easy enough task to do with a script, but I'm currious if it
> can be done with command line tools, instead.


If it can be done in a script it can almost certainly be done on the
command line.

Chris

  Réponse avec citation
Vieux 07/06/2006, 15h14   #3
Juha Laiho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: parsing log files

"yawnmoth" <terra1024@yahoo.com> said:
>Is there a way to make every IP address in a log file appear only once
>and have, beside that IP address, the number of times that that IP
>address appeared in the unparsed log file?
>
>eg. if 127.0.0.1 appears in a log file 30 times, is there a way to make
>a file that says something like...
>
>127.0.0.1: 30


If you're talking about the regular Apache httpd log format, then
this should be pretty much correct:

awk '{ hosts[$1]++ } END { for (host in hosts) { print host": "hosts[host]; } }' access_log

.... and formatted for readability:
awk '
{
hosts[$1]++
}

END {
for (host in hosts) {
print host": "hosts[host];
}
}' access_log


>It's an easy enough task to do with a script, but I'm currious if it
>can be done with command line tools, instead.


Well, I'd do it the same way in a script as well.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
  Réponse avec citation
Vieux 07/06/2006, 15h14   #4
Juha Laiho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: parsing log files

"yawnmoth" <terra1024@yahoo.com> said:
>Is there a way to make every IP address in a log file appear only once
>and have, beside that IP address, the number of times that that IP
>address appeared in the unparsed log file?
>
>eg. if 127.0.0.1 appears in a log file 30 times, is there a way to make
>a file that says something like...
>
>127.0.0.1: 30


If you're talking about the regular Apache httpd log format, then
this should be pretty much correct:

awk '{ hosts[$1]++ } END { for (host in hosts) { print host": "hosts[host]; } }' access_log

.... and formatted for readability:
awk '
{
hosts[$1]++
}

END {
for (host in hosts) {
print host": "hosts[host];
}
}' access_log


>It's an easy enough task to do with a script, but I'm currious if it
>can be done with command line tools, instead.


Well, I'd do it the same way in a script as well.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h20.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08938 seconds with 12 queries