Awk Question

William Weaver williamdweaver-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Mon Oct 29 17:44:46 UTC 2012


Hey folks,

So I'm still working on my awk skills. I'm trying to write a script that
allows me to pase a csv file of user rights and get all users that have a
specific right. Then using that list of users find all other rights those
users have.

Ex CSV:

UserName,Right
Bob,Add
Ben,Add
Ben,Delete
Tommy,Add
Sarah,Delete
Sarah,Edit

My result set if I search for users with Delete should look like

Ben,Delete
Sarah,Edit

This is what I have so far

BEGIN { FS = "," }

/Delete/ { Users[$1]=$2 }
/Delete/ {print $1, " - ", Users[$1]}

This gets me the list of all users with Delete and prints it for me. I've
been tinkering with a few ways to iterate through the array but I can't
seem to figure out how to do it. I think it requires two passes through the
file, one to generate the user list and one to generate the rights list,
but I'm kinda stuck. Anyone have any ideas.

Will Weaver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/legacy/attachments/20121029/33d909b7/attachment.html>


More information about the Legacy mailing list