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.
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.
You can use xml2 utility (https://manpages.debian.org/jessie/xml2/2xml.1) and starting in example from
<ANCFModel>
<UNITS force="NEWTON" mass="KILOGRAM" length="MILLIMETER" time="SECOND"/>
<GRID id="301019" 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 id="303001" 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 id="303002" 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 id="303003" 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 id="301020" 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 id="20000000" pid="10000" g1="301019" g2="303001"/>
<BEAM12 id="20000001" pid="10000" g1="303001" g2="303002"/>
<BEAM12 id="20000002" pid="10000" g1="303002" g2="303003"/>
<BEAM12 id="20000003" pid="10000" g1="303003" g2="301020"/>
<PBEAML id="10000" 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 id="3000000" e="210000" nu="0.3" rho="7.86e-06" YS="0.001" AP="2"/>
<CONN0 id="40000" gid="301020" conn="TTTTTT"/>
<CONN0 id="40001" gid="301019" conn="TTTTTT"/>
</ANCFModel>
and running
xml2 < input.xml | 2csv GRID @id @x @y @z @rx @ry @rz
you 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 gnumeric
It provides the CLI utility ssconvert which is, as the manpage says,
a command line spreadsheet format converter
To use it:
ssconvert SOURCE_FILE DEST_FILE
If 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.
There's a nice tool xq, similar to jq for JSON.
For Ubuntu 22.10 and newer:
sudo apt install xq
It supports using XPath expressions:
xq input.xml -x /user/@status
CSS selectors:
xq inpux.xml -q "body > p"
or converting to JSON then piping to jq if you're more familiar with its syntax.
Converting to XML -> JSON -> CSV:
xq inpux.xml -j | jq -r '(.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[] ]])[] | @csv'
I think the good solution is to get this github URL:
https://github.com/NetsecExplained/Nmap-XML-to-CSV
and then run this command, which will make a CSV file :
python3 xml2csv.py -f xmlfile.xml -csv anyname.csv
and i hope this work