O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required