Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

How to use Grep properly?

$
0
0
Hi Forum

Im making a script that takes multiple unix users and lists the users and the groups that the user is part of. the grouplist looks like this

Code:

grouplst="example_group1|example_group2|example_group3|example_group4"
I got most of it working but Im having trouble with a while loop that im using to filter out groups that dont matter.

Code:


        cntr3=1
        tempgrplst=$grouplist
        FilterIDgroups=""
        while (($cntr <= $groupcnt))
        do
                currentgroup=$(print $tempgrplst|awk -F '|' '{print $1}')
                cntr=$(($cntr + 1))
                print $IDgroups | grep $currentgroup >> $FilterIDgroups
                tempgrplst=${tempgrplst#*\|}
        done

I am trying to get only the groups that are in the grouplist to be in the variable FilterIDgroups. Sorry the variable names are bad, I had to change them to post them online.

Viewing all articles
Browse latest Browse all 16232

Trending Articles