Description
Csvt is csv transformer task that allow to:
Csvt task parameters
Attribute |
Description |
Value |
Required |
file |
input file |
.csv |
file or fileset |
tofile |
output file |
. |
tofile or todir |
todir |
output dir |
|
no |
template |
freemarker template |
.ftl |
yes (or inner template) |
overwrite |
overwrite output file |
true by default |
no |
ouputproperty |
output property |
|
no |
extension |
output extension (with fileset + todir) |
|
no |
delimiter* |
csv delimiter |
; by default |
no |
file1, file2 |
todo |
todo |
no |
Element |
Description |
Value |
Required |
fileset |
fileset element |
|
no |
template |
inner template element |
|
no |
parameter |
custom param value |
<parameter name=”” value=”"/> |
no |
foreach |
foreach element |
|
no |
* specific to csv task
Usages
Use cases
|
file2file |
set2set |
set2file |
file2set |
csvt |
csv2xml |
|
|
|
todo |
csv2md |
intersect, except, data migration ? |
concat, merge |
split mysqldump to xml |
- Transform csv datas to xml, see: file2file example.
- Manipulate csv files (intersect, except, …)
$ tree --charset=ascii csvt/
csvt/
|-- build.xml
|-- datas
| |-- file1.csv
| |-- file2.csv
|-- gen
| |-- except.csv
| |-- intersect.csv
`-- templates
|-- except.ftl
|-- intersect.ftl
ant file - build.xml
<project name="usages" xmlns:bj="antlib:org.bidji.taskdefs">
<target name="intersect" description="intersect csv files">
<bj:csvt file1="datas/file1.csv" file2="datas/file2.csv" tofile="gen/intersect.csv" template="templates/intersect.ftl" overwrite="true"/>
</target>
<target name="except" description="except csv files">
<bj:csvt file1="datas/file1.csv" file2="datas/file2.csv" tofile="gen/except.csv" template="templates/except.ftl" overwrite="true"/>
</target>
</project>
sku;description;manufacturer;material;size;color
sku01;desc01;man01;mat01;10;green
sku02;desc02;man02;mat02;10;yellow
sku03;desc03;man03;mat03;20;blue
sku;description;manufacturer;material;size;color
sku03;desc03;man03;mat03;20;blue
sku04;desc04;man04;mat04;40;green
sku05;desc05;man05;mat05;10;yellow
intersect.ftl
[#assign lines1 = csv1?api.lines()]
[#assign lines2 = csv2?api.lines()]
[#assign columns = csv1?api.columns()]
${print_header(columns)}
[#foreach line in lines1]
[#if csv2?api.has_line_with_col('sku',line.sku)]
${print_columns(columns,line)}
[/#if]
[/#foreach]
intersect.csv
sku;description;manufacturer;material;size;color
sku03;desc03;man03;mat03;20;blue