Jump to content

Number of Instances of a Specific Word in a Log File


feedyourself

Recommended Posts

I'm pretty sure this is really simple to do using the count function, but I am having a hard time finding examples on how to count the number of times a "SPECIFIC" word occurs in a file. For example, I just want to display how many times "this-word" occurs in "http://www.mysite.com/logfile.log". Any help would be appreciated.

You could also use substr_count() for seeing how many times this-word appears, if there is no need for a regular expression like above.

 

If the log file is big, then it might be better to move through the file a piece at a time and tally up the number of occurences of the word.

You could also use substr_count() for seeing how many times this-word appears, if there is no need for a regular expression like above.

 

If the log file is big, then it might be better to move through the file a piece at a time and tally up the number of occurences of the word.

 

Forgot about that one.  Probably much faster also.  But you may have problems with the word being part of a larger word, etc.  So you would want to add a space before and after, but then you have problems if the word is at the beginning or end of a line, etc...  Depends on what you want.

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.