2013-01-15 89 views
1

我試圖從mysqldump文件中提取數據,它的一個非常大的文件,將其恢復到數據庫將需要幾天,我試圖使用sed或awk來提取數據,如下所示awk打印從mysql轉儲文件

INSERT INTO `CallDetailRecord` VALUES (1706,1340684374803,1340684375823,1340684383013,'2253040012','2253040012','2253040012','4016487697',0,'225304001200','T',1,'','',0,7,1707,'LineTester','1101','[email protected]','',5060,'10.40.10.45',5060,'[email protected]','<sip:[email protected]:5060>;tag=sansay420992041rdb3914','<sip:[email protected]>;tag=100000342','200',0,'',0,NULL,'','^A',0,NULL,NULL); 
INSERT INTO `CallDetailRecord` VALUES (1707,1340684381526,1340684381526,1340684388725,'3109757108','3109757108','','4016487697',0,'','P',0,'','',0,7,1708,'LineTest','1101','[email protected]','10.40.10.40',5060,'',5060,'[email protected]','<sip:[email protected]>;tag=100000667','\"4016487697\" <sip:[email protected]>;tag=sansay420992112rdb2348','200',0,'',0,NULL,'','^A',0,NULL,NULL); 
INSERT INTO `CallDetailRecord` VALUES (1708,1340684380791,1340684381384,1340684389761,'3172850012','3172850012','3172850012','4016487697',0,'317285001200','T',1,'','',0,8,1709,'LineTester','1101','[email protected]','',5060,'10.40.10.45',5060,'[email protected]','<sip:[email protected]:5060>;tag=sansay420992099rdb5677','<sip:[email protected]>;tag=100000344','200',0,'',0,NULL,'','^A',0,NULL,NULL); 

我想輸出是

1706,1340684374803,1340684375823,1340684383013,'2253040012','2253040012','2253040012','4016487697',0,'225304001200','T',1,'','',0,7,1707,'LineTester','1101','[email protected]','',5060,'10.40.10.45',5060,'[email protected]','<sip:[email protected]:5060>;tag=sansay420992041rdb3914','<sip:[email protected]>;tag=100000342','200',0,'',0,NULL,'','^A',0,NULL,NULL 
1707,1340684381526,1340684381526,1340684388725,'3109757108','3109757108','','4016487697',0,'','P',0,'','',0,7,1708,'LineTest','1101','2.20.app_lin[email protected]','10.40.10.40',5060,'',5060,'[email protected]','<sip:[email protected]>;tag=100000667','\"4016487697\" <sip:[email protected]>;tag=sansay420992112rdb2348','200',0,'',0,NULL,'','^A',0,NULL,NULL 
1708,1340684380791,1340684381384,1340684389761,'3172850012','3172850012','3172850012','4016487697',0,'317285001200','T',1,'','',0,8,1709,'LineTester','1101','[email protected]','',5060,'10.40.10.45',5060,'[email protected]','<sip:[email protected]:5060>;tag=sansay420992099rdb5677','<sip:[email protected]>;tag=100000344','200',0,'',0,NULL,'','^A',0,NULL,NULL 

你的幫助是高度讚賞。

+0

如果DB恢復需要花費數天,無論如何大小,你做錯了什麼。文件有多大?轉儲是否包含「'ALTER TABLE'CallDetailRecord' DISABLE KEYS''之類的內容? – cmbuckley

回答

3

您可以使用:

文件a.awk:

BEGIN { FS = "VALUES \\(" }; 
"INSERT INTO \`CallDetailRecord\` VALUES" { sub(");$", "", $2); print $2 }; 

運行:

cat mysqldump_file | awk -f a.awk

+1

如果數據庫字段中有任何這些'FS'字符,這將不起作用。 – cmbuckley

+0

現在它應該工作... –

+0

看起來像它的工作,你知道我怎麼能在一條線上運行它? – Deano

2

使用SED:

sed -e 's/^INSERT INTO `CallDetailRecord` VALUES (//' -e 's/);$//' mysqldump_file 
+0

這也工作!非常感謝! – Deano