From: Alan Simon <SIMON () SHRSYS ! HSLC ! ORG>
To: tru64-unix-managers
Subject: Script Help
Date: Fri, 21 Mar 1997 19:52:44 +0000 [thread overview]
Message-ID: <96078609810566.tru64-unix-managers.marc@archive.invalid> (raw)
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
-------------------------------------------------------------------------------
next reply other threads:[~1997-03-21 19:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-03-21 19:52 Alan Simon [this message]
-- strict thread matches above, loose matches on Subject: below --
1999-06-16 15:26 Script help Mary J. Aumann
2000-03-23 13:01 Mary Aumann
2001-06-05 8:41 Klas.Erlandsson
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox