Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: string occurences

by tigervamp (Friar)
on Jun 13, 2001 at 03:45 UTC ( [id://87965]=note: print w/replies, xml ) Need Help??


in reply to string occurences

If you are running Unix,Linux,etc., and the url is in say the 3rd field (delimited by spaces as you said), then you can use simple shell tools, such as:
cat logfile|awk {'print $3'}|sort|uniq -c > counts.txt

This is the best approach, however, if your OS does not support such great tools, or you just want a Perl solution, this will work:

$occurences{(split)[2]}++ while (<>); foreach $url (keys %occurences) { print "$occurences{$url}\t$url\n"; }
change the subscript accordingly, then run the program:
<prompt> perl -w programname logfiles
tigervamp

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://87965]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 22:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found