Skip to content

Instantly share code, notes, and snippets.

@drodsou
Last active July 30, 2016 08:45
Show Gist options
  • Save drodsou/6635407 to your computer and use it in GitHub Desktop.
Save drodsou/6635407 to your computer and use it in GitHub Desktop.
[bash] List users of a group in linux (as primary and as secondary)
#!/bin/bash
GID=`cat /etc/group|grep $1| awk 'BEGIN { FS = ":" } ; { print $3 }'`
RE=".*:.*:.*:${GID}"
echo "As PRIMARY"
echo "----------"
cat /etc/passwd|grep $RE | awk 'BEGIN { FS = ":" } ; { print $1 }'| sort -f | awk '{print}' ORS=' '
printf "\n\nAs SECONDARY\n"
echo "-------------"
cat /etc/group|grep $1 | awk 'BEGIN { FS = ":" } ; { print $4 }' |sed 's/,/\n/g' | grep '[^\$]$' | sort -f | awk '{print}' ORS=' '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment