从mysql转储文件打印awk

时间:2013-01-15 19:14:16

标签: bash scripting sed awk

我正在尝试从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

非常感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

您可以使用:

档案a.awk:

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

运行:

cat mysqldump_file | awk -f a.awk

答案 1 :(得分:2)

使用sed:

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