I am trying to come up with some shell script code that does the following:
1) Reads each line in a text data file Each line is one record, and there are
multiple fields in each record, separated by semicolons.
2) Checks for a specified string within one of the fields.
3) If the string is present, then extract the contents of another field within
that line.
4) Concatenate each occurrence of the secondary field to an environment
varable.
For example, suppose I want to create the environment variable CARS that
contain all the cars that belong to a user (in this case, "bob"). The data
file looks like this:
camaro:red:bob
corvette:white:tom
miata:blue:bob
camry:gold:bill
The shell script would look for the string "bob" in the first line, third
piece. Finding it, the script would set CARS=camaro. It would then read the
second line and skip it, since it would not find the string "bob." It would
read the third line and set CARS=camaro,miata. It would then read the fourth
line, skip it, and quit, since it reached the end of the file.
Since my knowledge of shell scripting is limited, I have not been able to
figure out how to read each line of a file and act only on that line. Any and
all help is greatly appreciated.
-------------------------------------------------------------------------------
Alan Simon simon_at_hslc.org
Associate Director simon_at_shrsys.hslc.org
Health Sciences Libraries Consortium VOICE: (215) 222-1532
3600 Market Street, Suite 550 FAX: (215) 222-0416
Philadelphia, PA 19104
-------------------------------------------------------------------------------
Received on Fri Mar 21 1997 - 21:48:18 NZST