22.4. Viewing records

The user can either view all records or just a particular record. If the user wants to see all records then a simple cat and awk statement does it. If the records contain many fields then a more user-friendly output would be required, but this will suffice for our needs.

						if [ "$STR" = "all" ]; then 
  echo "Surname Name Employee Code" 
  echo "_______________________________" 
  cat $DBFILE |awk -F: '{print $2"\t"$3"\t\t"$1}' | more 
  return 0 
fi
					

The code to display a single record has already been covered in deletion and amendments. One slight change is the ability to print a record when the user chooses this option. Here’s the piece of code that sends a record to the printer:

						pr <<- MAYDAY RECORD No : $REC EMPLOYEE NUMBER : $CODE ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.