Shell script text file manipulation.

Hello,

I have mysql binary file which logs all the database queries and i to insert all queries log in to database. First i coverted binary file to text file. and start playing with it. Text file contains following queries, some samples are,

SET INSERT_ID=1;
INSERT INTO test (column1,column2,column3) VALUES ('column1value','
column2value ,'column3value')

SET INSERT_ID=2;
INSERT INTO test (column1,column2,column3) VALUES ('column1value','
column2value ,'column3value')

SET INSERT_ID=3;
INSERT INTO test1 (column1) VALUES ('column1value')

UPDATE test2 set column1 = Concat(chat, '
New User 49: bhjg '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '7ee090-88f0'

UPDATE test2 set column1 = Concat(chat, '
New User 49: sdf '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '7ee0-f0'

UPDATE test2 set column1 = Concat(chat, '
User Build27: this is good '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = 'f072-00e0'

UPDATE test2 set column1 = Concat(chat, '
User Build27: sdf '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = 'f06f-8f0'

UPDATE test2 set column1 = Concat(chat, '
New User 49: 2 '),seller_count = '0',buyer_count = '0',total_chat_lines = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '2311-rs'

SET INSERT_ID=4;
INSERT INTO test3 (
column1,
column2,
column3,

VALUES

(
column1value,
column2value,
column3value
)

1- I need terminator \(;\) at end of every query. Same as follows,
2- I need to append insert_id before any INSERT INTO query before column1 and it's value in VALUES section before column1value.

Same as follows. Can someone please help me how to get this. I tried sed/awk but no success yet.

SET INSERT_ID=1;
INSERT INTO test (insert_id,column1) VALUES (1,'column1value');

SET INSERT_ID=2;
INSERT INTO test (insert_id,column1,column2,column3) VALUES (2,'column1value','
column2value ,'column3value');

SET INSERT_ID=3;
INSERT INTO test1 (insert_id,column1,column2,column3) VALUES (3,'column1value','
column2value ,'column3value');

UPDATE test set chat = Concat(chat, '
New User 49: bhjg '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '7ee090-88f0';

UPDATE test set chat = Concat(chat, '
New User 49: sdf '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '7ee0-f0';

UPDATE test set chat = Concat(chat, '
User Build27: this is good '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = 'f072-00e0';

UPDATE test set chat = Concat(chat, '
User Build27: sdf '),seller_count = '0',buyer_count = '0',total = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = 'f06f-8f0';

UPDATE test set chat = Concat(chat, '
New User 49: 2 '),seller_count = '0',buyer_count = '0',total_chat_lines = LENGTH(chat) - LENGTH(REPLACE(chat, '
', '')),chat_end = now() where chat_id = '2311-rs';

SET INSERT_ID=4;
INSERT INTO test3 (
insert_id,
column1,
column2,
column3,

VALUES

(
4,
column1value,
column2value,
column3value
);

Thanks in advance.