Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!mrsvr.UUCP From: davej@mrsvr.UUCP (David Johnson x4-6506) Newsgroups: comp.unix.questions Subject: Re: Shell Database Management (?) Message-ID: <956@mrsvr.UUCP> Date: 31 Aug 89 16:31:30 GMT References: <10596@dasys1.UUCP> Sender: news@mrsvr.UUCP Distribution: usa Lines: 29 From article <10596@dasys1.UUCP>, by parsnips@dasys1.UUCP (David Parsons): > 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... > > David Parsons > Big Electric Cat Public UNIX I tried e-mail and it bounced and bounced and . . . Assume your "database" (file) is called database. Assume your state abbreviation is in a shell vbl called $abbr Try this: cut -c99,100 database | grep -n "$abbr" | sed 's/:..*$/p/' | ed - foo This should print all of the matching lines on stdout. Good Luck. -- David J. Johnson - Computer People Unlimited, Inc. @ GE Medical Systems gemed!python!davej@crd.ge.com - OR - sun!sunbird!gemed!python!davej "What a terrible thing it is to lose one's mind." - Dan Quayle