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!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
awk '{ countArray[$7]++ } END { for (j in countArray) print j,countArray[j] }' infile
Hope this helps.
Almost..! Almost..! (end of the reply is a list)
Now I get a nice list of all the e-mail addresses and how many e-mails that has been send from these addresses. But I need only the domains, now that's just a small thing to change in the code but I don't really know how to do that.
What I got is this:
awk 'BEGIN {$8~/^@./} {countArray[$8]++ } END { for (j in countArray) print j,countArray[j] }' seip1_1_.log
Because if you change countArray[$8]++ to countArray[$8~/^@./] it counts all the files with the specified filter. And if you change the way it prints, does it still counts correctly, or do they add up correctly?
Thanks, and thanks in advance again .
Sincerely yours,
S1GNZ
p.s, it might be handy to post a part of the outcome
You changed the output again. I'm not sure why you need/want 2 numbers behind the domain (Canada.com 50 0 vs Canada.com 50). I'm going to assume that you want to see the name of the domain and the amount (ie: Canada.com 50).
awk '/^[a-z]/ { gsub(/.*@/,"",$8) ; gsub(/>/,"",$8) ; countArray[$8]++ } END { for (j in countArray) print j,countArray[j] }' infile
/^[a-z]/ => only lines that start with a-z
gsub(/.*@/,"",$8) => strip all up to and including the @ from $8
gsub(/>/,"",$8) => strip the > (if present) from $8
countArray[$8]++ => increase counter for specific array
END { for (j in countArray) print j,countArray[j] } => print what is found.
Sample run:
Code:
$ cat infile
d k 1004083501.83190500 1004083501.156831500 1004083501.323597500 2950 <AMSTERDAM@Canada.com> local.AMSTERDAM_ZUIDOOST@Frankrijk.com 9238 81
m 1004083501.83190500 1004083501.331906500 2950 1 0 0 <AMSTERDAM@Canada.com> 9238 81
d k 1004083501.266650500 1004083501.323587500 1004083501.569195500 3076 <AMSTERDAM@Canada.com> remote.DIEMEN@Zwitserland.com 9246 512
m 1004083501.266650500 1004083501.583383500 3076 1 0 0 <AMSTERDAM@Canada.com> 9246 512
d k 1004083592.200293500 1004083592.265569500 1004083592.432499500 2295 <DUIVENDRECHT@Rhodesie.com> local.SCHIPHOL@Frankrijk.com 9293 81
m 1004083592.200293500 1004083592.440690500 2295 1 0 0 <DUIVENDRECHT@Rhodesie.com> 9293 81
d k 1004083592.375353500 1004083592.432487500 1004083592.728287500 2425 <DUIVENDRECHT@Rhodesie.com> remote.LUCHTHAVEN_SCHIPHOL@Zwitserland.com 9297 512
$ awk '/^[a-z]/ { gsub(/.*@/,"",$8) ; gsub(/>/,"",$8) ; countArray[$8]++ } END { for (j in countArray) print j,countArray[j] }' infile
Zwitserland.com 2
Canada.com 2
Frankrijk.com 2
Rhodesie.com 1
As this is homework I think we have provided you with all the tools you will need.
Should be easy enough to get your field 7 details if you look at the code.
btw. we are already using arrays. If you require the use of split then look at
the details in your text on that and you should be sweet.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.