[use case] Split

Description

The Split use case illustrates the txt task in a file2set usage :

When trying to compare two sql dump files, my visual compare tool crashed because they were too large. I decided to split them to compare each table independently.

Sample

Split sql dump files by tables.

$ tree --charset=ascii .
|-- build.xml
|-- datas
|   |-- file-to-split.sql
|-- gen
|   |-- split
|   |   |-- table1.sql
|   |   |-- table2.sql
|   |   `-- table3.sql

ant file - build.xml

<project name="usecases" xmlns:bj="antlib:org.bidji.taskdefs">
  	<target name="split" description="split big files">       
    	<bj:txtt file="datas/file-to-split.sql" tofile="gen/split/{table}.sql" overwrite="true">    		
    		<split when="line?trim?matches('DROP TABLE IF EXISTS `(.+?)`;')" set="table"/>
    	</bj:txtt>
	</target>
</project>

input file - file-to-split.sql

DROP TABLE IF EXISTS `table1`;
CREATE TABLE `table1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `todo` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='[truncate]';

-- MANY INSERT

DROP TABLE IF EXISTS `table2`;
CREATE TABLE `table2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `todo` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='[truncate]';

-- MANY INSERT

DROP TABLE IF EXISTS `table3`;
CREATE TABLE `table3` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `todo` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='[truncate]';

-- MANY INSERT

Other usages

Split file where line starts with | ends with | …

ant file - build.xml

<project name="usecases" xmlns:bj="antlib:org.bidji.taskdefs">
  	<target name="split" description="split big files">       
    	<bj:txtt file="datas/file-to-split.sql" todir="gen/split" overwrite="true">    		
    		<split where="line?trim?starts_with('DROP TABLE IF EXISTS')"/>
    	</bj:txtt>
	</target>
</project>