I have a file containing queries, each query ends with a “;”, I want to add a “COMMIT;BEGIN;” every 100 queries. Queries can take more than 1 line.
For instance:
INSERT INTO table
VALUES(...);
DELETE FROM table WHERE ...;
UPDATE table
SET ...;
So I want to replace every 100th ";" with "COMMIT;BEGIN;" (I know I have to add a BEGIN; at the beginning of the file and do something at the end but it's easy)
I need to do that in a shell script but I am not a Linux expert, is it better to use sed or awk (also the file size can be huge like 4GB)? I know the basics for those commands but I don't know if I can do what I want here...
Thanks!
If you can guarantee that the
;is at the end of the line, or if you don’t really care about lines with multiple;‘s, the easy solution (untested) is: