Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!unmvax!pprg.unm.edu!topgun.dspo.gov!lanl!cmcl2!dasys1!jpr From: jpr@dasys1.UUCP (Jean-Pierre Radley) Newsgroups: comp.unix.questions Subject: Re: Shell Database Management (?) Keywords: shell database Message-ID: <10650@dasys1.UUCP> Date: 6 Sep 89 20:08:57 GMT References: <10596@dasys1.UUCP> Reply-To: jpr@dasys1.UUCP (Jean-Pierre Radley) Distribution: usa Organization: TANGENT Lines: 27 In article <10596@dasys1.UUCP> parsnips@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@jpradley.uucp New York, NY 72160.1341@compuserve.com