Sponsored Content
Full Discussion: Xml to csv
Special Forums UNIX and Linux Applications Xml to csv Post 302993730 by drysdalk on Monday 13th of March 2017 05:24:58 PM
Old 03-13-2017
Hi,

I'm going to be the Devil's Advocate here and suggest something entirely different. If this is a one-time-only conversion you have to do, or if it's something you won't have to do on a regular basis, I'd honestly import the XML into a spreadsheet like MS Excel or OpenOffice/LibreOffice Calc, and then look at tidying it up and exporting it out as a CSV from there.

Of course if this is going to be an ongoing thing you anticipate needing to do many times per day forever then some kind of script would be desirable, but if it's not going to be something you have to spend lots of time doing then you may actually save more time using a spreadsheet than trying to write a script for this.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help to convert XML to CSV

Apologies if this has already been covered in this site somewhere, I did try looking but without any success. I am new to the whole XML thing, very late starter, and have a requirement to convert an XML fiule to a CSV fomat. I am crrently working on a Solaris OS. Does anyone have any suggestions,... (2 Replies)
Discussion started by: rossingi_33
2 Replies

2. Shell Programming and Scripting

CSV to XML

Iam pretty new to UNIX and would like to convert a CSV to an XML file using AWK scripts. Can anybody suggest a solution? My CSV file looks something like this : Serial No Growth% Annual % Commission % Unemployed % 1 35% 29% 59% 42% 2 61% ... (15 Replies)
Discussion started by: pjanakir
15 Replies

3. Shell Programming and Scripting

CSV processing to XML

Hi, i am really fresh with shell scripting and programming, i have an issue i am not able to solve to populate data on my server for Cisco IP phones. I have CSV file within the following format: ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;... (9 Replies)
Discussion started by: angel2008
9 Replies

4. Shell Programming and Scripting

XML to csv transformation

Hi, I want to write a perl script. Which should accept the xml file, one xsl file and the loaction. The perl script should process the xml file using the xsl file and puts the out put in specified location. For example: My.perl is perls cript. my.xml is like this <?xml version="1.0"... (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

5. Shell Programming and Scripting

XML to CSV specific

Hi , Please any one to help on ,extract this xml code into csv columns list. <SOURCEFIELD BUSINESSNAME ="" DATATYPE ="date" DESCRIPTION ="" FIELDNUMBER ="1" FIELDPROPERTY ="0" FIELDTYPE ="ELEMITEM" HIDDEN ="NO" KEYTYPE ="NOT A KEY" LENGTH ="19" LEVEL ="0" NAME ="BUSINESS_DATE"... (4 Replies)
Discussion started by: mohan705
4 Replies

6. Shell Programming and Scripting

Convert xml to csv

I need to convert below xml code to csv. I searched other posts as well but this post (_https://www.unix.com/shell-programming-scripting/174417-extract-parse-xml-data-statistic-value-csv.html) gives "sed command garbled" error. As of now I have written a long script to do it, but can it be done with... (7 Replies)
Discussion started by: dineshydv
7 Replies

7. Shell Programming and Scripting

How to convert xml to csv ?

I am in need of converting billions of XML into csv file to load data to DB, i have found the below code in perl but not sure why it's not working properly. CODE: #!/usr/bin/perl # Script to illustrate how to parse a simple XML file # and pick out all the values for a specific element, in... (1 Reply)
Discussion started by: rspwilliam
1 Replies

8. Shell Programming and Scripting

XML to CSV

I want to pharse below Xml Using Shell Scripting . Thanks in Advance <md> <neid> <neun>1523</neun> <nedn>XXX1212</nedn> <nesw>fffff12515</nesw> </neid> <mi> <mts>20141128001500</mts> <gp>550</gp> <mt>pmct1</mt> <mt>pmNo2</mt> <mt>pmNo3S</mt> <mv> <moid>Ma=1,Rn=1,Ul=311C</moid>... (6 Replies)
Discussion started by: pareshkp
6 Replies

9. UNIX for Beginners Questions & Answers

Xml to csv (again)

Hello, I have copied .xml code for a single item below. I am trying to extract three items (field indices*b244 (second occurrence), b203, and j151), so the desired output would be: 9780323013543 Manual of Natural Veterinary Medicine: Science and Tradition, 1e 68.95 A parallel solution,... (14 Replies)
Discussion started by: palex
14 Replies

10. Shell Programming and Scripting

Converting XML to CSV

Hello, For i while i have been using XMLStarlet to convert several XML files to CSV files. So far this always went fine. Today however i got a new XML format however but i cannot find out how to get the data i need. Below is part of the code where it shows the different format. What... (10 Replies)
Discussion started by: SDohmen
10 Replies
UNOCONV(1)																UNOCONV(1)

NAME
unoconv - convert any document from and to any LibreOffice supported format SYNOPSIS
unoconv [options] file [file2 ..] unoconv --listener [--server SRV] [--port PRT] [--connection CON] DESCRIPTION
unoconv is a command line utility that can convert any file format that LibreOffice can import, to any file format that LibreOffice is capable of exporting. unoconv uses the LibreOffice's UNO bindings for non-interactive conversion of documents and therefore needs an LibreOffice instance to communicate with. Therefore if it cannot find one, it will start its own instance for temporary usage. If desired, one can start a "listener" instance to use for subsequent connections or even for remote connections. OPTIONS
-c, --connection UNO connection string to be used by the client to connect to an LibreOffice instance, or used by the listener to make LibreOffice listen. Default connection string is "socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" -d, --doctype Specify the LibreOffice document type of the backend format. Possible document types are: document, graphics, presentation, spreadsheet. Default document type is 'document'. -e, --export Set specific export filter options (related to the used LibreOffice filter). eg. for the PDF output filter one can specify: -e PageRange=1-2 See the *EXPORT FILTERS* section. -f, --format Specify the output format for the document. You can get a list of possible output formats per document type by using the --show option. Default document type is 'pdf'. -i, --import Set specific import filters options (related to the used LibreOffice import filter based on the input filename). See the *IMPORT FILTERS* section. -l, --listener Start unoconv as listener for unoconv clients to connect to. -n, --no-launch By default if no listener is running, unoconv will launch its own (temporary) listener to make sure the conversion works. This option will abort the conversion if no listener is found, rather than starting our own listener. -o, --output If the argument is a directory, put the converted documents in this directory. If multiple input files are provided, use it as a basename (and add output extension). Otherwise use it as the output filename. --pipe Use a pipe as an alternative connection mechanism to talk to LibreOffice. -p, --port Port to listen on (as listener) or to connect to (as client). Default port is '2002'. -s, --server Server (address) to listen on (as listener) or to connect to (as client). Default server is 'localhost'. --show List the possible output formats to be used with -f. --stdout Print converted output file to stdout. -t, --template Specify the template to use for importing styles from. This can be very useful if you have a corporate identity you have to apply to every document you distribute. -T, --timeout When unoconv starts its own listener, try to connect to it for an amount of seconds before giving up. Increasing this may help when you receive random errors caused by the listener not being ready to accept conversion jobs. -v, --verbose Be more and more and more verbose. ARGUMENTS
You can provide one or more files as arguments to convert each of them to the specified output format. IMPORT FILTERS
Depending on the used input file, a different LibreOffice import filter is automatically used by unoconv. This import filter can be influenced by the -i option that, depending on the filter used, accepts different arguments. It is not always clear what import filter options you can provide, the import dialog in LibreOffice for the filter you ar using might give a good indication as to what you can expect as import filter options. The reference is LibreOffice's documentation, for spreadsheets it is described at: http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options but we will look into some examples. DEFAULT IMPORT FILTER OPTIONS
The default import filter for many imports (eg. Lotus, dBase or DIF) accepts as the only argument the input encoding-type, so if you require utf-8 (76) you can do: -i FilterOptions=76 For a list of posible encoding types, you can use the above link to find the possible options. o FilterOptions TEXT IMPORT FILTER OPTIONS
The Text import filter accepts a FilterOptions setting holding the input encoding. o FilterOptions CSV IMPORT FILTER OPTIONS
The CSV import filter accepts a FilterOptions setting, the order is: separator(s),text-delimiter,encoding,first-row,column-format For example you might want to use this for a real comma-separated document: -i FilterOptions=44,34,76,2,1/5/2/1/3/1/4/1 which will use a comma (44) as the field separator, a double quote (34) as the text delimiter, UTF-8 (76) for the input encoding, start from the second row and use the specified formats for each column (1 means standard, 5 means YY/MM/DD date) If you like to use more than one separator (say a space or a tab) and use the system's encoding (9), but with no text-delimiter, you can do: -i FilterOptions=9/32,,9,2 For a list of posible encoding types, you can use the above link to find the possible options. o FilterOptions EXPORT FILTERS
In contrast to import filters, export filters can have multiple named options, although it is not always clear what options are available. It all depends on the version of LibreOffice. The export dialog you get in LibreOffice might give you a clue about what is possible, each of those widgets represents an option. TEXT EXPORT FILTER OPTIONS
The Text export filter accepts a FilterOptions setting holding the output encoding. o FilterOptions The order of the arguments is: encoding,field-seperator,text-delimiter,quote-all-text-cells,save-cell-content-as-shown CSV EXPORT FILTER OPTIONS
The CSV export filter accepts various arguments, the order is: field-seperator(s),text-delimiter,encoding For example you might want to use this for a real comma-separated document: -e FilterOptions=44,34,76 which will use a comma (44) as the field separator, a double quote (34) as the text delimiter, UTF-8 (76) for the export encoding, start from the second row and use the specified formats for each column (1 means standard, 5 means YY/MM/DD date) If you like to use more than one separator (say a space or a tab) and use the system's encoding (9), but with no text-delimiter, you can do: -e FilterOptions=9/32,,9 For a list of posible encoding types, you can use the above link to find the possible options. o FilterOptions PDF EXPORT FILTER OPTIONS
The PDF export filter is likely the most advanced export filter in its kind with a myriad of options one can use. The export filter options are described in a separate document, or on LibreOffice's wiki at: http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export For example one can specify: -e PageRange=1-2 Here is a list of all options, however for more details please look in filters.txt: o AllowDuplicateFieldNames o CenterWindow o Changes o ConvertOOoTargetToPDFTarget o DisplayPDFDocumentTitle o DocumentOpenPassword o EmbedStandardFonts o EnableCopyingOfContent o EnableTextAccessForAccessibilityTools o EncryptFile o ExportBookmarks o ExportBookmarksToPDFDestination o ExportFormFields o ExportLinksRelativeFsys o ExportNotes o ExportNotesPages o FirstPagOnLeft o FormsType o HideViewerMenubar o HideViewerToolbar o HideViewerWindowControls o InitialPage o InitialView o IsAddStream o IsSkipEmptyPages o Magnification o MaxImageResolution o OpenBookmarkLevels o OpenInFullScreenMode o PageLayout o PageRange o PDFViewSelection o PermissionPassword o Printing o Quality o ReduceImageResolution o ResizeWindowToInitialPage o RestrictPermissionPassword o Selection o SelectPdfVersion o UseLosslessCompression o UseTaggedPDF o UseTransitionEffects o Watermark o Zoom GRAPHICS EXPORT FILTER OPTIONS o Height o Resolution o Width BMP EXPORT FILTER OPTIONS o Compression o RLEEncoding JPEG EXPORT FILTER OPTIONS o ColorDepth o Quality PBM/PGM/PPM EXPORT FILTER OPTIONS o Encoding PNG EXPORT FILTER OPTIONS o Compression o InterlacedMode GIF EXPORT FILTER OPTIONS o InterlacedMode o Transparency EPS EXPORT FILTER OPTIONS o ColorFormat o Compression o Preview o Version EXAMPLES
You can use unoconv in standalone mode, this means that in absence of an LibreOffice listener, it will starts its own: unoconv -f pdf some-document.odt One can use unoconv as a listener (by default localhost:2002) to let other unoconv instances connect to it: unoconv --listener & unoconv -f pdf some-document.odt unoconv -f doc other-document.odt unoconv -f jpg some-image.png unoconv -f xsl some-spreadsheet.csv kill -15 %- This also works on a remote host: unoconv --listener --server 1.2.3.4 --port 4567 and then connect another system to convert documents: unoconv --server 1.2.3.4 --port 4567 ENVIRONMENT VARIABLES
UNO_PATH specifies what LibreOffice pyuno installation unoconv needs to use eg. /opt/libreoffice3.4/basis-link/program EXIT STATUS
Normally, the exit status is 0 if the conversion ran successful. If an error has occured, the return code is most likely an error returned by LibreOffice (or its interface, called UNO) however, the error never translates to something meaningful. In case you like to decipher the LibreOffice errCode, look at: http://cgit.freedesktop.org/libreoffice/core/tree/tools/inc/tools/errcode.hxx http://cgit.freedesktop.org/libreoffice/core/tree/svtools/inc/svtools/sfxecode.hxx http://cgit.freedesktop.org/libreoffice/core/tree/svtools/inc/svtools/soerr.hxx Using the above lists, the error code 2074 means: Class: 1 (ERRCODE_CLASS_ABORT) Code: 26 (ERRCODE_IO_INVALIDPARAMETER or SVSTREAM_INVALID_PARAMETER) And the error code 3088 means: Class: 3 (ERRCODE_CLASS_NOTEXISTS) Code: 16 (ERRCODE_IO_CANTWRITE) SEE ALSO
convert(1), file(1), odt2txt BUGS
unoconv uses the UNO bindings to connect to LibreOffice, in absence of a usable socket, it will start its own LibreOffice instance with the correct parameters. Note Please see the TODO file for known bugs and future plans. REFERENCES
unoconv is very useful together with the following tools: Asciidoc http://www.methods.co.nz/asciidoc/ asciidoc-odf http://github.com/dagwieers/asciidoc-odf docbook2odf http://open.comsultia.com/docbook2odf/ A list of possible import and export formats is available from: OpenOffice 2.1 http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_2_1 OpenOffice 3.0 http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0 AUTHOR
Written by Dag Wieers, <dag@wieers.com[1]> RESOURCES
Main web site: http://dag.wieers.com/home-made/unoconv/ COPYING
Copyright (C) 2007 Dag Wieers. Free use of this software is granted under the terms of the GNU General Public License (GPL). AUTHOR
Dag Wieers <dag@wieers.com> Author. NOTES
1. dag@wieers.com mailto:dag@wieers.com 0.4 20 october 2010 UNOCONV(1)
All times are GMT -4. The time now is 11:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy