Avatar of blnukem
blnukem asked on

Count All Search Terms

Hi All

I have several folders with text files in this structure:
 
log/9.5.2007/search.txt
log/9.6.2007/search.txt
log/9.7.2007/search.txt
log/9.8.2007/search.txt
log/9.9.2007/search.txt

The file search.txt contains search words used on the site for that day in this structure:

Date|IP|Page|SearchWords
Date|IP|Page|SearchWords
Date|IP|Page|SearchWords
Date|IP|Page|SearchWords


What I need to do is open all of the search.txt files and count how may times a keyword was search for and list the keywords in numerical order from highest to lowest count.

So if during the day Widgets was searched for 3 times and Toywidgets was search for 1 time the script would output:

Widgets 3
Toywidgets 1
Perl

Avatar of undefined
Last Comment
Tintin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ozo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Tintin

Or a non-Perl solution on Unix/Linux systems

awk -F'|' '{print $NF}' log/*/search.txt | sort | uniq -c
ozo

Do you want all log/*/search.txt files, or just
log/9.5.2007/search.txt
log/9.6.2007/search.txt
log/9.7.2007/search.txt
log/9.8.2007/search.txt
log/9.9.2007/search.txt


awk -F'|' '{print $NF}' log/*/search.txt | sort | uniq -c | sort -nr

Tintin

Good pickup ozo on me missing the 'sort -rn'
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23