Because I want to use the variable in various context throughout the program and don't want to have to re-parse the file again
Main Topics
Browse All TopicsStore the fields of one record for all records of a variable length ascii file in variables in a Korn Shell script.
For example, the format of the file is:
field1, field2, field3, .. .field n where n may be any number and the number differs between records.
There may be 1-n records in the file.
For each record, the fields should be assigned to a variable $FIELD1, $FIELD2, ... $FIELDN; The variables shall be assigned for each record in turn; provide a variable indicating the number of fields in the record (
Variables available in a while or for loop shall be:
$numberoffields, $Field1, $Field2, ... $FieldN).
Thank you for your trouble,
C:)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If I have a count of the number of fields in the comma delimited record (==n) I will be able to use it as an index into the array; of course, I am thinking of loading an array. I would look for something like
for (i=first record; i<=last record; i++)
{
for (j=firstfield; j<=lastfieldofcurrent record; j++)
{
array[ij]= field j in record read from file
... do my stuff
}
}
array[i][ would be a ksh variable;
PLease let me know if this is not clear.
Thank you for your trouble,
C:)
I am sorry I haven't responded to ozo and omarfarid sooner; neither solution worked on the solaris ksh.
I finally got the following to work:
IFS=,
while read record
do
count=0
for i in $record
do
if [[ $count = 0 ]]; then
testcase=$i
elif [[ $count = 1 ]]; then
testcaseID=$i
elif [[ $count = 2 ]]; then
rootID=$i
fi
let count+=1
done
echo $testcase $testcaseID $rootID
done < automap.csv
IFS=$OIFS
Since your syntax wasn't quite correct for my environment though your help did get me on the right track (and google web pages) I won't award the total number of points and give each of you 100 points.
Business Accounts
Answer for Membership
by: TintinPosted on 2008-08-21 at 16:32:23ID: 22285249
I'd question your approach. Why do you need each field in a separate variable? What type of processing are you going to be doing?