Some time ago I had to work with some MySQL database dumps generated by mysqldump(1), lacking a version control software (which fortunately hasn't been needed) more specific, the one used was git(7). Now, git allows to make diff across versions, but this (at least by default) is made line by line so mysqldumps get a lot of data changes even if only a row is the one changed to solve this issue this program was written sqlsplit.c.

The program isn't too polished, it has a main function that only opens the file and another which (with the help of two macro *_*) simulates something like a state automata (actually with a stack), the compilation is simple

1
gcc sqlsplit.c -o sqlsplit

So, for example, if the input is

1
2
3
4
5
set autocommit=0;
INSERT INTO `input_table` VALUES (1,'Title 1','File 1','Type','NULL','Date 1'),(2,'Another title','Another file, too','Type, you know','Language','9999'),(3,'A third title','File with \' too.heh','Some, types','NULL','Tomorrow');
/*!40000 ALTER TABLE `input_table` ENABLE KEYS */;
UNLOCK TABLES;
commit;

Doing this...

1
./sqlsplit intput.sql output.sql

We'd get something more legible

1
2
3
4
5
6
7
8
set autocommit=0;
INSERT INTO `input_table` VALUES
    (1,'Title 1','File 1','Type','NULL','Date 1'),
    (2,'Another title','Another file, too','Type, you know','Language','9999'),
    (3,'A third title','File with \' too.heh','Some, types','NULL','Tomorrow');
/*!40000 ALTER TABLE `input_table` ENABLE KEYS */;
UNLOCK TABLES;
commit;

And thats all, of course if we'd want to take or show data on the terminal (for example to take or return compressed files) the files to use would be /dev/stdin for the input and/or /dev/stdout for the output.