|
|
|
|
||||||
| comp.info.servers.unix Web servers for UNIX platforms. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"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) |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"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) |
|
![]() |
| Outils de la discussion | |
|
|