From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078609810566.tru64-unix-managers.marc@archive.invalid> From: Alan Simon Date: Fri, 21 Mar 1997 19:52:44 +0000 To: tru64-unix-managers Subject: Script Help X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078609810566 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@hslc.org Associate Director simon@shrsys.hslc.org Health Sciences Libraries Consortium VOICE: (215) 222-1532 3600 Market Street, Suite 550 FAX: (215) 222-0416 Philadelphia, PA 19104 -------------------------------------------------------------------------------