0)

sort -t: +1nr -1.3 +1.2n input-data

1)

#!/bin/sh
for i in $*
do ypcat passwd | cut -d: -f1,4 | grep -w $i
done

2)

#!/bin/sh
for i in `cat /tmp/usernames`
do ypcat passwd | cut -d: -f1,4 | grep -w $i 
done

3)

groupid=`ypcat passwd | cut -d: -f1,4 | grep -w cs_kcc | cut -d: -f2`
ypcat passwd | cut -d: -f1,4 | grep ${groupid} | cut -d: -f1

4)

#!/bin/sh
if [ $# -eq 0 ]
then
   echo usage: dumb_calc integer [integer]
else
   if [ $# -eq 1 ]
   then result=`expr $1 \* $1`
   else result=`expr $1 \* $2`
   fi
   echo ${result}
fi

5)

#!/bin/sh

# Script for creating random number sequence
# for COMP111 Lab session
#
# By Tommy Ng and others

# determine the filename where the seed is stored
seedfile=/tmp/random$USER

# handle the arguments according to four different cases
if [ $# -eq 1 ]
then
	if [ $1 -le 0 -o $1 -gt 31104 ]
	then
		seed=10000
	else
		seed=$1
	fi
else
	if [ -f $seedfile ]
	then
		seed=`cat $seedfile`
	else
		seed=10000
	fi
fi

# generate the random number
random=`expr \( 625 \* $seed + 6571 \) \% 31104`

# display the random number and save it in the seed file
echo $random | tee $seedfile