#!/usr/bin/nawk -f # @(#) Revision 1.2 - 07/05/96 # extract # # Usage: extract start=rec1 end=rec2 [file] # Example: extract start=3 end=22 car0919b.cgn # # Description: Prints out records between (and including) range start - end # # ============================================================================= # Andrea Whitlock, Mobius Software Services # whitlock@mobius-soft.com # # Bug reports, questions, and suggestions should be emailed to: # mobius@mobius-soft.com # # This software is provided under the terms of the GNU copyleft # (ftp://prep.ai.mit.edu/pub/gnu/COPYING-2.0), without a warranty # of any kind. Use at your own risk. # ============================================================================= # BEGIN { if (ARGC == 1) { print "usage: extract start= end= []" print "example: extract start=3 end=22 car0919b.cgn" print " will print records 3 through 22 from file car0919b.cgn to stdout" print "example: cat reclist | sort | extract start=2 > reclist.new" print " will print records 2 through EOF from stdin (reclist) to reclist.new" exit } } { if (!start && !end) { print "usage: extract start= end= " print "example: extract start=3 end=22 car0919b.cgn" print " will print records 3 through 22 from file car0919b.cgn to stdout" exit } if (!start) start = 1 rec++ if (rec == start) output = 1 if (output == 1) print $0 if (rec == end) exit }