#linux环境
cat temp.sql | sed -n '/###/p'| sed 's/### //g;s/\/\*.*/,/g;s/DELETE FROM/;INSERT INTO/g;s/WHERE/SELECT/g;' |sed -r 's/(@17.*),/\1;/g' | sed 's/@1=//g'| sed 's/@[1-9]=/,/g' | sed 's/@[1-9][0-9]=/,/g' > mysqllogOK.sql
windows环境
'==========================
'用VBS实现 MYSQL binglog DELETE转INSERT
'==========================
function replaceregex(patern,str,tagstr)
dim regex,matches
set regex=new regExp
regex.pattern=patern
regex.IgnoreCase=true
regex.global=true
matches=regex.replace(str,tagstr)
replaceregex=matches
end function
'======Mysql binlog DELETE转INSERT================
'VBS打开文本文件
Set oldStream =CreateObject("ADODB.Stream")oldStream.CharSet="utf-8"oldStream.OpenoldStream.LoadFromFile("temp.sql") 'binLog生成的DELETE原日志文件
oldText =oldStream.ReadText()
newText=replace(oldText,"### DELETE FROM",";INSERT INTO")
newText=replace(newText,"### WHERE","SELECT")
newText=replace(newText,"###","")
newText=replace(newText,"@1=","")
newText=replaceregex("\@[1-9]=",newText,",")
newText=replaceregex("\@[1-9][0-9]=",newText,",")oldStream.Close
'VBS保存文件
Set newStream =CreateObject("ADODB.Stream")newStream.Type=2 'Specify stream type - we want To save text/string data.
newStream.Charset="utf-8" 'Specify charset For the source text data.
newStream.Open 'Open the stream And write binary data To the object
newStream.WriteText newText
newStream.SaveToFile"temp1.sql",2 'DELETE转成INSERT以后的新的SQL文件名
newStream.Close