Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting sql insert with sed, line cuts

I've been reading on stackoverflow about the use of sed for extracting data from sql dumps, being more accurate, the final purpose is to extract inserts for an specific table in order to restore only that table.

I’m using this:

sed -n '/LOCK TABLES `TABLE_NAME`/,/UNLOCK TABLES/p' dump.sql > output.sql

The problem that I’m having is that we have inserts on 1 line that are more than 50Mb long, so while extracting the insert, the output gets cut before the end of the line. like:

......
(4
3458,'0Y25565137SEOEJ','001','PREPAR',1330525937741,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(43459,'666

I tried to use awk and even simple grep and the result is the same, the line gets cut.

Edit: Im using this on a sql dump from mysql and the system I'm working on is a Centos 5.2

like image 216
Ikaro Avatar asked Nov 14 '22 09:11

Ikaro


1 Answers

You can try awk and see if it's better (I think so) :

awk '/LOCK TABLES `TABLE_NAME`/,/UNLOCK TABLES/' dump.sql > output.sql
like image 142
Gilles Quenot Avatar answered Dec 11 '22 15:12

Gilles Quenot