Displaying the highest ranking IP address
You should now realize some powers of awk
and how immense the language structure is in itself. The data we have been able to produce from the 30K line file is truly powerful and easily extracted. We just need to replace the field we have used before with $1
. This field represents the client IP address. If we make use of the following code, we will be able to print each IP Address and also the number of times it has been used to access the web server:
{ ip[$1]++ } END { for (i in ip) print i, " has accessed the server ", ip[i], " times." }
We want to be able to extend this to show only the highest ranking of IP address, the address that has been used the most to access the site. The work, again, will mainly be in the END
block and will make use of a comparison against the current highest ranking address. The following file can be created and saved as ip.awk
:
{ ip[$1]++ } END { for (i in ip) if ( max < ip[i] ) { max...