1

我正在尝试从 mysqldump 文件中提取数据,它是一个非常大的文件,将其还原到数据库需要几天时间,我正在尝试使用 sed 或 awk 来提取数据,如下所示

INSERT INTO `CallDetailRecord` VALUES (1706,1340684374803,1340684375823,1340684383013,'2253040012','2253040012','2253040012','4016487697',0,'225304001200','T',1,'','',0,7,1707,'LineTester','1101','57.6.app_linetester.1102@10.40.10.170','',5060,'10.40.10.45',5060,'1000003415761102_app_linetester@10.40.10.170','<sip:12253040012@10.40.10.45:5060>;tag=sansay420992041rdb3914','<sip:14016487697@10.40.10.170>;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','2.20.app_linetest.1103@10.40.10.170','10.40.10.40',5060,'',5060,'212122542-0-2277160422@74.112.124.121','<sip:3109757108@10.40.10.170>;tag=100000667','\"4016487697\" <sip:4016487697@10.40.10.40>;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','57.13.app_linetester.1102@10.40.10.170','',5060,'10.40.10.45',5060,'10000034357131102_app_linetester@10.40.10.170','<sip:13172850012@10.40.10.45:5060>;tag=sansay420992099rdb5677','<sip:14016487697@10.40.10.170>;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','57.6.app_linetester.1102@10.40.10.170','',5060,'10.40.10.45',5060,'1000003415761102_app_linetester@10.40.10.170','<sip:12253040012@10.40.10.45:5060>;tag=sansay420992041rdb3914','<sip:14016487697@10.40.10.170>;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_linetest.1103@10.40.10.170','10.40.10.40',5060,'',5060,'212122542-0-2277160422@74.112.124.121','<sip:3109757108@10.40.10.170>;tag=100000667','\"4016487697\" <sip:4016487697@10.40.10.40>;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','57.13.app_linetester.1102@10.40.10.170','',5060,'10.40.10.45',5060,'10000034357131102_app_linetester@10.40.10.170','<sip:13172850012@10.40.10.45:5060>;tag=sansay420992099rdb5677','<sip:14016487697@10.40.10.170>;tag=100000344','200',0,'',0,NULL,'','^A',0,NULL,NULL

非常感谢您的帮助。

4

2 回答 2

3

您可以使用:

文件 a.awk:

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

跑:

cat mysqldump_file | awk -f a.awk

于 2013-01-15T19:26:51.820 回答
2

使用 sed:

sed -e 's/^INSERT INTO `CallDetailRecord` VALUES (//' -e 's/);$//' mysqldump_file
于 2013-01-15T19:54:36.480 回答