shell script to...
Jutta Degener
jde at uwbln.uucp
Sun Apr 14 18:27:54 AEST 1991
Neil Greene writes:
> I have a file that contains drug names and next to the drug name is the drug
> group.
>
> > Dipyrone Analgesic
> > [...]
>
> I need a shell script that will read from another (ascii) data file,
> find an occurance of a DRUG_NAME, write the line to another (ascii) file
> and append the appropriate DRUG_TYPE to the new line.
`write all occurances of <name> into a file, followed by <group>' is
something sed can do well. A statement like
"/name/s/$/ <group>/w file"
or "/name/s/$/ <group>/p" for stdout
works fine.
Your input file with the drug pairs is almost a `program' you could feed
to sed. One would want to add a few slashes, but that, again, could be
accomplished using sed, for example with
s/\([-a-zA-Z0-9]*\)[ ]*\([-a-zA-Z0-9]*\)/-e \/\1\/s\/$\/\ \2\/p/p
which turns
foo bar
into
-e /foo/s/$/ bar/p
if I'm not mistaken (quote until works).
Now you have three possibilities left:
(a) forget it, get pearl
(b) figure out how to get those darn spaces across and end up using
something like
eval sed -n `sed -n -e "s/\([-a-zA-Z0-9]*\)[ ]*\([-a-zA-Z0-9]*\)/
-e \'\/\1\/s\/$\/\ \2\/p'/p" < $1`
which actually seems to work (joined into one line) from sh,
given the drug file as first argument
(c) get bitten by the command line length limit, use a tempfile for
the sed program or go back to step (a)
Still waiting for the awk solution,
Jutta
--
#include <std/disclaimer.h> Jutta Degener jutta at tub.cs.tu-berlin.de (owl:hugs.)
More information about the Comp.unix.questions
mailing list