title: Shell Script- each unique user
body: <p>I have a homework assignment: "for each unique user, report which group they are a member of and when they last logged in"</p>
  
  <p>So far I have:</p>
  
  <pre><code>#!/bin/sh
  
  echo "Your initial login:"
  who | cut -d' ' -f1 | sort | uniq
  
  echo "Now is logged:"
  whoami
  
  echo "Group ID:"
  id -G $whoami
  
  case $1 in
     "-l") last -Fn 10 | tr -s " " ;;
     *)    last -Fn 10 | tr -s " " | egrep -v '(^reboot)|(^$)|(^wtmp a)|(^ftp)' | cut -d" " -f1,5,7 | sort -uM | uniq -c
  esac
  </code></pre>
  
  <p>My question is: how I can show the each unique user? The script above only show the more recent user logged in the system, but I need all unique users.</p>
  
  <p>Can anyone help?</p>