For loops with multiple variables

Hi script gurus.

I have need to know how to use for loop with multiple variable.

Basically lets take for example /etc/passwd file has following entries

The above cat command will basically first greps the real users that have email addresses then converts ':' to '+' then using cut to extract the userid and email addresses using the '+' as a delimiter to produce the below output

sparcguy sparcguy@unix.com
aixguy aixguy@unix.com
hpuxguy hpuxguy@unix.com

Assuming I pipe the above output to a file called /tmp/list

I know I can just cat the file to display the above but how to I use for loop to display it instead?

the above does not seems to work, does anybody knows how to use multiple variables in a for i in `cat file` loop?

thx in advance

Is something like this what you're looking for?

sed 's/\([^:]*\).*+\([^:]*\).*/\1 \2/' /etc/passwd | while read name email
do
  echo "$name"
  echo "$email"
  ...
  ...
done

Hi Franklin52,

Thanks for your replies. Well your method works but I need to do some more further manipulation. I'm trying to rewrite the solaris password aging script "pwage" for hpux Trusted systems. I already figured out the calculation part I just need to find a way for the script to be able to reply to the user that's why I'm trying to use a for loop.

http://www.unix.com/shell-programming-scripting/33854-check-password-age.html?bcsi_scan_9DF8B7809DCC25ED=x3TVLmO5mutY4fcVp4y3XB4AAAAwTGsP&bcsi_scan_filename=33854-check-password-age.html

Not sure if this is what you're looking for, but it's unnecessary to use a temporary file for the userid.
You could do something like this:

MAXAGE=90

while IFS=: read uid dummy
do
  for j in `find /tcb -name "$uid" -exec ls -1 {} \;`
  do
    LASTPWCHG=`awk -F: '/u_succhg/{print $3}' "$j"`
    DAYSEC=86400
    DAWNOFTIME=`/usr/contrib/bin/perl -e 'print int(time)'`
    SECSAGO=`echo "$DAWNOFTIME - $LASTPWCHG" | bc`
    DAYSAGO=`echo "$SECSAGO/$DAYSEC" | bc`
    LEFTDAYS=`echo "$MAXAGE - $DAYSAGO" | bc`
    if [ "$LEFTDAYS" -le 7 ]
    then
       # show a reminder and send to user email address.... etc
    fi
  done
done < /etc/passwd

thanks for your reply again dude.

I found a less painful way.

no need to loop

Will share the script for password aging for hpux trusted servers in another thread.