-1
<application name="DAP_OPP" csversion="4.0" product="ESSBASE_PRODUCT" redeployType="listed Dimensions Full" dimCount="1">
    <Dimension name="Scenario" DataStorage="DynamicCalc" extendedMemberComment="@@SYSMEMBER=3,-1 @@SYSDBV=Scenario" HierarchyType="Stored" csversion="4.0">
        <Member name="2010 Reporting Year" Consolidation="~" HierarchyType="Disabled">
            <Member name="11_2010_Forecast_Budget_LS">
                <Alias table="Default">2010 Forecast</Alias> 
            </Member>
            <Member name="Prior Year4 Actual" extendedMemberComment="@@SYSMEMBER=3,7 @@SYSDBV=Current Year Actual">
                <Alias table="Default">2010_Actual</Alias> 
                <UDA>a0</UDA> 
                <UDA>2010AA</UDA> 
            </Member>
            <Member name="LS_2010_Tax Allocation" Consolidation="~" extendedMemberComment="@@SYSMEMBER=3,7 @@SYSDBV=LS_2010_Tax Allocation">
                <UDA>b6.45</UDA> 
            </Member>
            <Member name="LS_2010_Actual" Consolidation="~" extendedMemberComment="@@SYSMEMBER=3,7 @@SYSDBV=LS_2010_Actual">
                <UDA>a3.4</UDA> 
            </Member>
            <Member name="10_2010_Budget_LS" Consolidation="~" extendedMemberComment="@@SYSMEMBER=3,7 @@SYSDBV=10_2010_Budget_LS">
                <UDA>a6.5</UDA> 
            </Member>
            <Member name="Current Year Budget" Consolidation="~" extendedMemberComment="@@SYSMEMBER=3,7 @@SYSDBV=Current Year Budget">
                <UDA>b2</UDA> 
                <UDA>200631</UDA> 
            </Member>
            <Member name="Current Year Forecast" Consolidation="~" extendedMemberComment="@@SYSMEMBER=3,7 @@SYSDBV=Current Year Forecast">
                <UDA>b3</UDA> 
                <UDA>200520</UDA> 
            </Member>
            <Member name="Adjustments" Consolidation="~" extendedMemberComment="@@SYSMEMBER=3,7 @@SYSDBV=Adjustments">
                <UDA>c4</UDA> 
            </Member>
        </Member>
    </Dimension>
</application>

I need to generate below output file using unix,

Scenario,2010 Reporting Year,~,11_2010_forecast_Budget_LS,2010 Forecast
Scenario,2010 Reporting Year,~,Prior Year4 Actual,2010_Actual,a0,2010AA
Scenario,2010 Reporting Year,~,LS_2010_Tax Allocation,~,b6.45
Scenario,2010 Reporting Year,~,LS_2010_Actual,~,a3.4
Scenario,2010 Reporting Year,~,10_2010_Budget_LS,~,a6.5
Scenario,2010 Reporting Year,~,Current Year Budget,~,b2,200631
Scenario,2010 Reporting Year,~,Current Year Forecast,~,b3,200520
Scenario,2010 Reporting Year,~,Adjustments,~,b3,200520
Xstian
  • 8,184
  • 10
  • 42
  • 72

1 Answers1

0

Don't use a shell script. Really.

You might be able to hack something up, with sed or awk or something like that, but it'll be very specific to this case, be very brittle (the slightest change to the input would probably make it break), be very hard to develop further, and wouldn't teach you anything (in the sense that you won't be able to re-use the knowledge you've gained).

Use XSLT:

  • libxml is a C library which includes a command-line program (xsltproc) which implements XSLT 1.0, and which can therefore process XML files into anything you like. Disadvantage: it only implements XSLT 1.0; XSLT 2.0 and 3.0 are larger languages, but have some very helpful features.
  • Saxon is a Java library for XML parsing; the library comes in several variants. This implements multiple versions of XSLT. Disadvantage: it suffers from the non-negligible startup time that all Java programs have, so it's a little less comfortable to use interactively (but this is a minor inconvenience in almost all circumstances).

There are other XSLT implementations, but these two are probably the best-known.


Most currently-fashionable languages have XML parsing libraries. The alternative to using XSLT is to parse the XML in a program, do ... stuff with it, and then use the same library to serialise it in some way. But ‘use XSLT’ is the nearest thing to ‘do it on the command line’.

Norman Gray
  • 11,978
  • 2
  • 33
  • 56
  • Well, the [documentation page for that](http://xmlstar.sourceforge.net/docs.php) says it supports XSLT, so yes, I suppose so. It appears that it uses `libxml` to do its work. – Norman Gray Apr 14 '15 at 12:54