linux - Insert stuff at every nth occurence of a character in a file -
i have file containing queries, each query ends ";", want add "commit;begin;" every 100 queries. queries can take more 1 line.
for instance:
insert table values(...); delete table ...; update table set ...; so want replace every 100th ";" "commit;begin;" (i know have add begin; @ beginning of file , @ end it's easy)
i need in shell script not linux expert, better use sed or awk (also file size can huge 4gb)? know basics commands don't know if can want here...
thanks!
if can guarantee ; @ end of line, or if don't care lines multiple ;'s, easy solution (untested) is:
awk '/;/{ count+=1 } {print} count==100 { print "commit; begin"; count=0 }'
Comments
Post a Comment