Shell Database Management (?)

Jean-Pierre Radley jpr at dasys1.UUCP
Thu Sep 7 06:08:57 AEST 1989


In article <10596 at dasys1.UUCP> parsnips at dasys1.UUCP (David Parsons) writes:
>I would like to use a Bourne shell script to extract records from a simple
>database of fixed-length fields terminated with a new-line character.
>The problem... the database consists of addresses... positions 99 and 100
>in each record contain a two-position abbreviation for the state.  It's easy
>to get cut to read those two characters, and grep to identify the state I
>want to extract, but how the ^#$&! do you then copy the ENTIRE record 
>thus identified to another file???  Using grep alone is no good because 
>the abbreviation appears in various other places in the record...

This is a one-liner for awk:

:statefinder
awk '
	{  if ("'$1'" == substr($0, 99, 2) )  print }
' $2


Thus if characters 99 and 100 of your line contain the state,
then typing
	
	statefinder NY datafile

should do what you want.
-- 
Jean-Pierre Radley					      jpr at jpradley.uucp
New York, NY					      72160.1341 at compuserve.com



More information about the Comp.unix.questions mailing list