Hi folks, having some trouble with awk. Maybe one could help me with this script.
As you see in the comments, this file should extract IP Numbers from an apache logfile, to "nslookup" their names.
But it seems that I have a mistake saving the actual content
on a "stack" to have it compared with the "new" value.
Could someone lead me to the right direction ?
TIA Oliver
#! /usr/bin/awk -f
#
# used to extract the ip-numbers of an apache-logfile
# a logfile looks like this line
# 212.185.238.10 - - [18/Dec/2001:15:41:39 +0100] "GET / HTTP/1.1" 200 271 "-" "Mozil
# several lines with the same IP numer appearing, until the number changes
# the file is already grouped with sort
# This should extract only different IP numbers
begin { pstack=" " } # just clean the var pstack (shall hold the previous value)
{
printf ("FIELD1= %s\n", $1) # show us, what's in the first field
infield=$1 # make var infield the content of $1 (the IP number)
if($pstack == $infield) # if $pstack is the same as infield
# (in the first run it is " " so it should not come in)
# in the second and further run, there should be the value
# from the previous line, which could be the same
{
print "similar to pstack\n"
}
else # if there is a difference, show the new number
# (write in a file)
{
print "different!"
$pstack= $1 # set $pstack the new value
}
}
As you see in the comments, this file should extract IP Numbers from an apache logfile, to "nslookup" their names.
But it seems that I have a mistake saving the actual content
on a "stack" to have it compared with the "new" value.
Could someone lead me to the right direction ?
TIA Oliver
#! /usr/bin/awk -f
#
# used to extract the ip-numbers of an apache-logfile
# a logfile looks like this line
# 212.185.238.10 - - [18/Dec/2001:15:41:39 +0100] "GET / HTTP/1.1" 200 271 "-" "Mozil
# several lines with the same IP numer appearing, until the number changes
# the file is already grouped with sort
# This should extract only different IP numbers
begin { pstack=" " } # just clean the var pstack (shall hold the previous value)
{
printf ("FIELD1= %s\n", $1) # show us, what's in the first field
infield=$1 # make var infield the content of $1 (the IP number)
if($pstack == $infield) # if $pstack is the same as infield
# (in the first run it is " " so it should not come in)
# in the second and further run, there should be the value
# from the previous line, which could be the same
{
print "similar to pstack\n"
}
else # if there is a difference, show the new number
# (write in a file)
{
print "different!"
$pstack= $1 # set $pstack the new value
}
}