if I have a XML file on local disk, which command is need to convert file in CSV?
And from XLSX or XLS to CVS?
Thanks.
12 Answers
You can use xml2 utility () and starting in example from
<ANCFModel> <UNITS force="NEWTON" mass="KILOGRAM" length="MILLIMETER" time="SECOND"/> <GRID x="328.217224" y="543.844177" z="0.000000" rx="0.000000 -1.000000 0.000000" ry="1.000000 0.000000 0.000000" rz="0.000000 0.000000 1.000000"/> <GRID x="328.217224" y="518.844177" z="0.000000" rx="0.000000 -1.000000 0.000000" ry="1.000000 0.000000 0.000000" rz="0.000000 0.000000 1.000000"/> <GRID x="328.217224" y="493.844177" z="0.000000" rx="0.000000 -1.000000 0.000000" ry="1.000000 0.000000 0.000000" rz="0.000000 0.000000 1.000000"/> <GRID x="328.217224" y="468.844177" z="0.000000" rx="0.000000 -1.000000 0.000000" ry="1.000000 0.000000 0.000000" rz="0.000000 0.000000 1.000000"/> <GRID x="328.217224" y="443.844177" z="0.000000" rx="0.000000 -1.000000 0.000000" ry="1.000000 0.000000 0.000000" rz="0.000000 0.000000 1.000000"/> <BEAM12 pid="10000" g1="301019" g2="303001"/> <BEAM12 pid="10000" g1="303001" g2="303002"/> <BEAM12 pid="10000" g1="303002" g2="303003"/> <BEAM12 pid="10000" g1="303003" g2="301020"/> <PBEAML mid="3000000" type="BAR" dim1a="5.000000" dim2a="50.000000" dim1b="5.000000" dim2b="50.000000" nx="5" ny="3" nz="3" ngx="5" ngy="4" ngz="4"/> <MAT1 e="210000" nu="0.3" rho="7.86e-06" YS="0.001" AP="2"/> <CONN0 gid="301020" conn="TTTTTT"/> <CONN0 gid="301019" conn="TTTTTT"/>
</ANCFModel>and running
xml2 < input.xml | 2csv GRID @id @x @y @z @rx @ry @rzyou will have
+--------+------------+------------+----------+-----------------------------+----------------------------+----------------------------+
| 301019 | 328.217224 | 543.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
| 303001 | 328.217224 | 518.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
| 303002 | 328.217224 | 493.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
| 303003 | 328.217224 | 468.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
| 301020 | 328.217224 | 443.844177 | 0.000000 | 0.000000 -1.000000 0.000000 | 1.000000 0.000000 0.000000 | 0.000000 0.000000 1.000000 |
+--------+------------+------------+----------+-----------------------------+----------------------------+----------------------------+ I assume you'd like to convert spreadsheet(-like) xml files. Then it looks like the Gnumeric package can do what you need.
To install it:
sudo apt install gnumericIt provides the CLI utility ssconvert which is, as the manpage says,
a command line spreadsheet format converter
To use it:
ssconvert SOURCE_FILE DEST_FILEIf instead you want a more "generic XML to CSV converter", I cannot think of a pre-packaged tool installable in Ubuntu.
A quick googling suggest this GitHub repository. It's java based, but it should work ok in Ubuntu.