ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I would approach it by first sorting the file by the first field. (man sort... remember to set the -t flag to tell it to use a comma as field separator.) This would place all the "John Does" on consecutive lines.
You could then use an awk script to accumulate a list of IP addresses for identical first field. Only print a line when the first field is different from the previous, again making sure to specify "," as field separator.
This might get you started, sorry that I don't have time to try a sample script as it would be quite involved.
Further, the OP is also asking us to "print" the "5" ($2 in awk) only once.
To take further Vrajgh's example
Since the file is now sorted, you need not even accumulate it, but printf without "\n". You
The awk now has the following pseudo code.
BEGIN {a=$1}
{
If $1 != a then ( printf("\n") ; a=$1; printf("%s,%s,",$1,$2) }
printf("%s",$3) ;
}
END {printf("\n"); }
I have real base knowledge as for scripting...I tried to build something starting with sort and the awk but didn't made it. I'm trying to develop my scripting skills...but anyone can help me? My boss is asking for this thing every damn morning...
I have real base knowledge as for scripting...I tried to build something starting with sort and the awk but didn't made it. I'm trying to develop my scripting skills...but anyone can help me? My boss is asking for this thing every damn morning...
and? where's your code? its your work remember? not ours.. furthermore , some of use have already shown you ways to do it. now pull up your socks and show us something.
don't just follow blindly the pseudocode AnanthaP gives you. Its wrong in syntax. Read the gawk doc (see my sig) to learn how to use awk. Or see here for simpler one.
Sometime people don't have the time to learn awk and need to resolve problems quickly. That's what are forums for also. I don't need you to bring me internet documentation, google does an excellent job at that. I needed directions to build this darn thing by tonight...
Let's drop it, you can go back to you're teaching class...I'll solve my problem another way...
Sometime people don't have the time to learn awk and need to resolve problems quickly. That's what are forums for also. I don't need you to bring me internet documentation, google does an excellent job at that. I needed directions to build this darn thing by tonight...
Let's drop it, you can go back to you're teaching class...I'll solve my problem another way...
one sentence says it all. you are just too lazy, even with already given hints.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.