Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!uakari.primate.wisc.edu!ames!sun-barr!oliveb!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: Shell Database Management (?) Message-ID: <4885@omepd.UUCP> Date: 1 Sep 89 15:47:18 GMT References: <10596@dasys1.UUCP> <956@mrsvr.UUCP> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Distribution: usa Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 40 In-reply-to: davej@mrsvr.UUCP (David Johnson x4-6506) In article <956@mrsvr.UUCP>, davej@mrsvr (David Johnson x4-6506) writes: | 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. Hmmppph. I saw a guy removing a screw with the claw of a claw hammer the other day. You remind me of him. Wrong set of tools, dude! I can cut those lines in one process: awk 'substring($0,99,2) == "'"$abbr"'"' database (I might be off by one on the substring function...) Just another UNIX toolsmith (who can tell a claw hammer from a straight screwdriver...), -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel, Hillsboro, Oregon, USA | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/