Awk Question

William Weaver williamdweaver-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Mon Oct 29 19:01:22 UTC 2012


For the actual work (which I can't give the actual data out because the
buisness nature of it. There are alot more rights than the 3 that I put in.
I would end up defining enough arrays that it wouldn't be worth it unless I
could define the array name dynamically as well.

$2[$3]=1

I've been looking at the getline functionality and it seems to be the right
path but now I have a boss moving up the time line on me so I may have to
do this in a combonation of excel/by hand instead of getting the time to
actually learn something useful out of this. I'll still be doing it
afterword if for nothing else than my own edification.

Will Weaver

On Mon, Oct 29, 2012 at 2:49 PM, William Park <opengeometry-FFYn/CNdgSA at public.gmane.org> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/legacy/attachments/20121029/9dba6980/attachment.html>


More information about the Legacy mailing list