INSERT INTO `db`.`table`
VALUES (
39741633
49302045
0
44
'{"CustomerName":"S","CustomerMobile":"8","CustomerEmail":"","VersionId":"5","CityId":"2","CampaignId":"1","InquirySourceId":"3","Eagerness":"-1","ApplicationId":"2","BranchId":"3","AssignedDealerId":"2","DMSInqNo":"45"}'
NULL
0
'2021-11-09 19:11:50'
NULL
1
29
NULL
);
INSERT INTO `db`.`table`
VALUES (
39741635
49970365
0
30
'{"CustomerName":"A","CustomerEmail":"As@gmail.com","CustomerMobile":"9","VersionId":"6","InquirySourceId":"1","Eagerness":"-1","IsCorporate":"z","CampaignId":"8","BranchId":"3","ApplicationId":"1","Location":{"City":{"CityId":"1"},"Area":{"AreaId":"4"}},"CouponCode":null,"CwOfferId":"0","AssignedDealerId":"0","PinCode":""}'
NULL
0
'2021-11-09 19:11:51'
NULL
1
29
NULL
);
I have these insert statements extracted out of binlogs. They were not exactly like this, I have changed them a little, but I am stuck. I need to convert them into actual insert statements. If you see I need to add commas at end of each line after the second line (INSERT INTO db
.table
VALUES (), for each insert statement. That means add commas after two lines till 11 lines, then again start after INSERT INTO and repeat.
I tried to google and found this
sed '/INSERT/{n;n;n;n;n;s/$/,/}' teststring.txt
--> this will put comma on fifth line after insert. The problem is if I run it again for the sixth line
sed '/INSERT/{n;n;n;n;n;n;s/$/,/}' teststring.txt
, then it replaces the earlier comma placed by the first SED command
This is how the file should look.
INSERT INTO `db`.`table`
VALUES (
39741633,
49302045,
0,
44,
'{"CustomerName":"S","CustomerMobile":"8","CustomerEmail":"","VersionId":"5","CityId":"2","CampaignId":"1","InquirySourceId":"3","Eagerness":"-1","ApplicationId":"2","BranchId":"3","AssignedDealerId":"2","DMSInqNo":"45"}',
NULL,
0,
'2021-11-09 19:11:50',
NULL,
1,
29,
NULL
);
INSERT INTO `db`.`table`
VALUES (
39741635,
49970365,
0,
30,
'{"CustomerName":"A","CustomerEmail":"As@gmail.com","CustomerMobile":"9","VersionId":"6","InquirySourceId":"1","Eagerness":"-1","IsCorporate":"z","CampaignId":"8","BranchId":"3","ApplicationId":"1","Location":{"City":{"CityId":"1"},"Area":{"AreaId":"4"}},"CouponCode":null,"CwOfferId":"0","AssignedDealerId":"0","PinCode":""}',
NULL,
0,
'2021-11-09 19:11:51',
NULL,
1,
29,
NULL
);
How can I achieve this?