The task is to display a list of groups from /etc/group that certain user is member of. User name is passed as a parameter. My current code:
#!/bin/bash
cat /etc/group | grep -w "$1" | cut -d ":" -f1
The problem is that there are certain lines that contain user name but they are not groups that user is member of. Example: syslog:x:106: and adm:x:4:syslog,username. The only thing I want as a result is adm but my current code will also output syslog. Is there a way to correct it?