从mysql备份文件中提取指定表

Standard

mysqldump file:

awk 'BEGIN{temp_str = ""; find = "false"; end = "false";}{temp_str=temp_str""$0 ; if(match($0,"INSERT INTO `tb_name`") >0 ) find="true"; if(match($0,";") >0 ) end = "true";  if(end=="true" && find=="false"){ temp_str=""; end="false"}; if(end=="true" && find=="true") {print temp_str; end="false"; find="false"}}' .sql > _awk.sql

binlog file:

awk 'BEGIN{temp_str = ""; find = "false"; end = "false";}{temp_str=temp_str""$0 ; if(match($0,"tb_name") >0 ) find="true"; if(match($0,";") >0 ) end = "true";  if(end=="true" && find=="false"){ temp_str=""; end="false"}; if(end=="true" && find=="true") {print temp_str; end="false"; find="false"}}' .sql > _awk.sql

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.