![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Find total size for some files? | helen008 | UNIX for Dummies Questions & Answers | 5 | 06-09-2008 12:01 PM |
| sort files by date, delete oldest, if total size bigger than | scarfake | Shell Programming and Scripting | 2 | 05-21-2008 08:02 AM |
| total occ. | gander_ss | Shell Programming and Scripting | 6 | 05-09-2008 03:54 AM |
| total number of files which have "aaa" in files whose names are File*_bbb* | sudheshnaiyer | UNIX for Dummies Questions & Answers | 1 | 08-16-2007 02:34 PM |
| Running Total | lyoncc | Shell Programming and Scripting | 9 | 08-07-2007 11:24 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
grep running total/ final total across multiple files
Ok, another fun hiccup in my UNIX learning curve. I am trying to count the number of occurrences of an IP address across multiple files named example.hits. I can extract the number of occurrences from the files individually but when you use grep -c with multiple files you get the output similar to :
adventure.hits:6 adverts.hits:16 blog.hits:19 books.hits:8 cds.hits:7 contact.hits:2 crime.hits:11 dvds.hits:8 fantasy.hits:9 fiction.hits:12 food.hits:10 gadgets.hits:14 games.hits:21 gardening.hits:6 health.hits:13 hotlist.hits:20 index.hits:83 jobs.hits:4 mags.hits:14 music.hits:9 news.hits:5 nonfiction.hits:16 novels.hits:9 people.hits:10 recent.hits:17 sales.hits:4 sf.hits:16 software.hits:18 sport.hits:13 test.hits:6 is there a simple way to get grep to skip all the above information and just give the final total of occurences across all of the files? I know it's probably staring me in the face but I just cant get my head around a simple and effective way to do it. Regards. |
|
||||
|
basically I have narrowed the file down into a list of IP address. then I search through each of the hit files using awk and grep
a .hit file contains an entry per line: 192.168.2.1 Tue nov 22 20:30:45 GMT 2005 The code I have so far is: IPList is a list of IP addresses cat IPList | while read LINE do TOTALHITS=`grep -c "$LINE" *.hits` echo $TOTALHITS $LINE >> totalIPHits done but the output of the grep command is as shown in the original post. how would I go about awking such a statement to keep total? |
|
||||
|
something like this maybe
awk '{ Array[$1]++ } END{ for (I in Array) { print I, Array[I]} }' *.hit This will scan multiple files that would be shown with an ls *.hit listing, then, using the first field as its key, maintain a total of the hits in the Array. then, at the End, for each value in the array, print the Array Key followed by the count. |
|
||||
|
or simply ,
cat file1 file2 file3 file4 ............... | grep -c <ip_address> |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|