Awk Question
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Mon Oct 29 18:49:06 UTC 2012
On Mon, Oct 29, 2012 at 01:44:46PM -0400, William Weaver wrote:
> 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
:-) If one pass is acceptable for your assignment, try something like
this. First, set up "rights" arrays, ie.
Add[Bob] = 1
Add[Ben] = 1
Delete[Ben] = 1
Add[Tommy] = 1
Delete[Sarah] = 1
Edit[Sarah] = 1
where Delete array has "Ben" and "Sarah". Second, check if other arrays
have "Ben" and "Sarah". Here, "Ben" shows up in Add/Delete arrays, and
"Sarah" shows up in Delete/Edit arrays.
--
William
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list