[last updated - 27 July 2003]
This is a very useful tool for printing out a limited number of pages from all your output listings. It is especially useful for Clinical so they can see a sample of what they are going to get without wading through a few trees. You specify a start and end page and the files you want to extract those pages from. It uses awk and I'll introduce you to a new feature of awk - the BEGIN block.
#!/bin/sh # Script : pages # Version : 1.0 # Author : Roland Rashleigh-Berry # Date : 27 July 2003 # Contact : roland@rashleigh-berry.fsnet.co.uk # Purpose : To print out a selected range of pages from multiple files # SubScripts : none # Notes : none # Usage : pages 2 4 *.lst # #================================================================================ # PARAMETERS: #-pos- -------------------------------description-------------------------------- # 1 start page number # 2 end page number # 3 files #================================================================================ # AMENDMENT HISTORY: # init --date-- mod-id ----------------------description------------------------- # #================================================================================ # This is public domain software. No guarantee as to suitability or accuracy is # given or implied. User uses this code entirely at their own risk. #================================================================================ if [ $# -lt 3 ] ; then echo "Usage: pages start-page end-page *.lst" 1>&2 exit 1 fi spage=$1 epage=$2 shift shift while [ $# -gt 0 ] ; do awk 'BEGIN{pgcnt=1}{if (index($0,"\014")>0) pgcnt++; if (pgcnt>"'$epage'") exit; if (pgcnt>="'$spage'") {print $0}}' $1 shift done
The BEGIN block only works when awk starts up. In this case it is setting up a page count variable that gets initialised to 1. Outside this BEGIN block you will see that the page count gets incremented (using the ++ notation) when it finds the octal number \014 in the input record that awk refers to as $0. If it exceeds the specifed end page then the utility will exit. But if the page is between the start and end page then it will print the full record to standard output. It does this for every file supplied to it. Output from this procedure should be redirected to a file which can then be printed.
Go back to the home page.
E-mail the macro and web site author.