vendredi 24 juillet 2020

Assigning a value from a text file to variable in shell in loop

I have text file, which will contain 1 record and more. I need to assign each row values of a column to a variable during each loop for example :

test.txt:

1234,12,IN,John,xyz@hotmail.com
1111,10,SA,John,xyz@hotmail.com
2222,11,EU,John,xyz@hotmail.com
3333,13,CN,John,xyz@hotmail.com
4444,14,US,John,xyz@hotmail.com

Delete statement :

delete from table1.test where id=$var1 and code=$var2 and country='$var3'

loop 1 - delete query will use the below variable values

$var1=1234, $var2=12, $var3=IN 
delete statement 

loop 2 - delete query will use the below variable values

$var1=1111, $var2=10, $var3=SA 
delete statement 

loop 3 - delete query will use the below variable values

$var1=2222, $var2=11, $var3=EU
delete statement 

loop 4 - delete query will use the below variable values

$var1=3333, $var2=13, $var3=CN 
delete statement 

Aucun commentaire:

Enregistrer un commentaire