Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Large XML file (600MB) and i want to convert that into CSV through Terminal Commands. I have tried to convert the XML into TXT through xml2 command using the following syntax.

xml2 < BIG.xml > BIG.txt

My XML Fromat is

    <UserDetailsText>Individual Details</UserDetailsText>
    <ApplicationDetailsText>Conflict Resolution Details</ApplicationDetailsText>
        <ApplicationName>John Perry</ApplicationName>
        <Department>Information Technology</Department>

I want these fields in CSV file separated with a Pipe (|)

Date | CaseNo | FirstName | Surname | ApplicationNo | ApplicationName | ApplicationDate | ApplicationStatus

Also if i want to do the file through a PHP file will i need a shell script to perform that.

share|improve this question

Use XSL to perform the transformation to the exact format you need; e.g.,

<xsl:stylesheet version="1.0"
<xsl:output method="text" encoding="iso-8859-1"/>
<xsl:strip-space elements="*" />

<xsl:template match="/ReportDetails">
  <xsl:value-of select="Date"/><xsl:text>|</xsl:text>
  <xsl:value-of select="CaseNo"/><xsl:text>|</xsl:text>
  <xsl:apply-templates select="UserDetails" />

<xsl:template match="/ReportDetails/UserDetails">
  <xsl:value-of select="FirstName"/><xsl:text>|</xsl:text>
  <xsl:value-of select="Surname"/><xsl:text>|</xsl:text>

<!-- etc -->

And then given the above (e.g., in foo.xsl to transform original xml document foo.xml):

$ xsltproc  foo.xsl  foo.xml 

(The devil is in the details of the xsl... there are numerous ways to implement this...)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.