Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I was looking an older post (http://superuser.com/questions/279891/list-all-members-of-a-group-mac-os-x/395738#395738) and I tried the code that the user Arne Stenström posted.

members () { dscl . -list /Users | while read user; do printf "$user "; dsmemberutil checkmembership -U "$user" -G "$*"; done | grep "is a member" | cut -d " " -f 1; };

It works perfectly but the output is a list of the users uid. I'm trying to get the RealNames too in order to have a list with the uid and the RealName at the output.

I tried infinite things and options but I'm not able to get it. I know that I can list the RealName of an user with this code:

dscl . -list /Users/username RealName

I can't find the way to join both ideas to reach the wanted result.

Could you please help me?

Thank you very much.

share|improve this question

2 Answers 2

There's probably something wrong with this or an easier way to do the same thing, but could you just run dscl . -read /Search/Users/username RealName for all usernames?

g=admin; dscl . -list /Users | while read l; do printf %s "$l "; dsmemberutil checkmembership -U $l -G $g; done | grep 'is a member' | cut -d' ' -f1 | while read l; do echo "$l $(dscl . -read /Users/$l RealName | tail -n1 | cut -c2-)"; done

share|improve this answer
    
Hi Lauri, it worked perfectly! Thank you very much. One more question, is there any option to use a "tab" as delimitation between the uid and the RealName? –  Ricard Jun 21 '13 at 10:52
    
Just replace echo "$l $ with echo $l$'\t'"$ or something. –  Lri Jun 21 '13 at 11:48
up vote 0 down vote accepted

Thanks to Lauri's code and help I finally found the code that creates a CSV file with the UID and RealName of the users of a OD GROUP. It works perfectly for me :)

g=nameofthegroup; dscl . -list /Users | while read l; do printf %s "$l "; dsmemberutil checkmembership -U $l -G $g; done | grep 'is a member' | cut -d' ' -f1 | while read l; do echo -e "$l \t $(dscl . -read /Users/$l RealName | tail -n1 | cut -c2-)"; done > /path/file.csv

Thank you very much Lauri for your help!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.