You can do something like this :
Code:
#
# Function : FileFields input_file ...
# Output : Fields assignments for each field of each record
#
FileFields() {
awk '
# First record of input_file contains field names
# which are memorized in the col[] array.
FNR==1 {
col_count=NF;
for (f=1; f<=NF; f++)
col[f] = $f;
next;
}
# Data record
# Assignment for each file is generated in the form :
# field_name='field_value';
{
for (f=1; f<=col_count; f++)
printf("%s=\047%s\047; ", col[f], $f);
print "";
}
' $*
}
#
# Proceed input files
# The input files are read with the FileFields function
#
FileFields cols.txt | \
while read fields
do
eval $fields
# Proceed record
# Displays assignments of variables as an example
echo $fields
done
The result of the execution of this script with your input datas is :
ID='065'; Designation='Soap'; Price='2.00'; Stock='30';
ID='780'; Designation='Parachute'; Price='56.00'; Stock='2';