Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Really new to unix so might not be able to explain my problem clearly but here goes.
I have two variables MONTH and YEAR and need to look through a directory containing 15 or so files for find lines that contain both variables. Once this is done I need the output to show the file name and the number of times both variables appear in each file.
So far I have my grep command at:
grep $MONTH ~/webhits/* | grep -c -H $YEAR
When I run this command I get an output of "(standard input):[the number of times both my variables appear in the whole directory] but I need it broken down into the number of times it appears in each file.
Thanks in advance for any help
Last edited by UnixNewbie91; 04-27-2012 at 06:07 PM.
Each file contains the number of web hits for a fake website from a number of different made up IP addresses. Some of the IP addresses appear twice in the same file so the hit from this IP address is counted multiple times. If I wanted to only count the hit from each IP once (so get the number unique hits) how would I do this.
Here is an example of the file if it helps
220.127.116.11 Mon May 07 08:11:50 GMT 2007
18.104.22.168 Thu May 10 01:59:33 GMT 2007
22.214.171.124 Thu May 10 05:14:58 GMT 2007
So for these three hits I want to count the hits from IP address 126.96.36.199 as one unique hit.
I believe that's getting out of the realm of bash/grep. Something like awk would probably be powerful enough to do it. You could either leave your current grep in tact and use awk to find the unique IPs from the match, or use awk to do both steps. I'm not an awk expert though, so I'll let somebody else chime in there.
Basically I have to write a script that looks at the files which are all set up like the example I gave and then put into a table the name of the folder, the number of hits in a given time frame which are sorted in descending order and then the number of unique hits (number of different IP addresses.