I have a file with the following format
--TABLEA_START--
field1=data1;field2=data2;field3=data3
--TABLEA_END--
--TABLEB_START--
field1=data1;field2=data2;field3=data3
--TABLEB_END--
--TABLEA_START--
field1=data1;field2=data2;field3=data3
field1=data1;field2=data2;field3=data3
--TABLEA_END--
I have a string
lookup="TABLEA.field2,TABLEA.field3,TABLEB.field2"
I would like to construct a lookup table/something similar containing the tables and their respective fields so that I can achieve the following.
if the table fields is indicated in the string, i would like to set the the relevant field value to blank i.e field1=; and save it to the file without affecting other data. Changes to TABLEA.field1 will not affect TABLEB.field1. There can be more than one instance of the same table (like TableA shown above.
My logic is as such
IFS=";"
do
for i in $lookup
table_name=${i%%.*} #table name
table_field=${i#*.} # field name
sed -n "/$table_START--/,/--$table_END--/p" file #extract data between start and end
loop table fields
sed "s/$table_field=[^=]*;/$table_field=;/;$//g"
done
How can I achieve this and put all this together? Any help will be greatly appreciated.