Shell Database Management (?)

Randal Schwartz merlyn at iwarp.intel.com
Sat Sep 2 01:47:18 AEST 1989


In article <956 at mrsvr.UUCP>, davej at mrsvr (David Johnson x4-6506) writes:
| From article <10596 at dasys1.UUCP>, by parsnips at 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 at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/



More information about the Comp.unix.questions mailing list