XML-Text Parsing Using shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting XML-Text Parsing Using shell scripting
# 1  
Old 10-02-2012
XML-Text Parsing Using shell scripting

HI Guys,

I have to parse below xml file :-

PHP Code:
[CODE]<xn:SubNetwork id="ONRM_ROOT_MO_R">
            <
xn:MeContext id="LP101">
                <
xn:ManagedElement id="1">
                    <
xn:VsDataContainer id="1">
                        <
xn:attributes>
                            <
xn:vsDataType>vsDataEquipment</xn:vsDataType>
                            <
es:vsDataEquipment/>
                        </
xn:attributes>
                        <
xn:VsDataContainer id="1">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                 <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:el>80</es:el>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="2">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:el>30</es:el>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="3">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:el>80</es:el>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                    </
xn:VsDataContainer>
                </
xn:ManagedElement>
            </
xn:MeContext>
            <
xn:MeContext id="LP102">
                <
xn:ManagedElement id="1">
                    <
xn:VsDataContainer id="1">
                        <
xn:attributes>
                            <
xn:vsDataType>vsDataEquipment</xn:vsDataType>
                            <
es:vsDataEquipment/>
                        </
xn:attributes>
                        <
xn:VsDataContainer id="1">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:el>20</es:el>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="2">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:el>100</es:el>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="3">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
xn:vsDataFormatVersion>EricssonSpecificAttributes.12.26</xn:vsDataFormatVersion>
                                    <
es:vsDataRetSubUnit>
                                    <
es:el>80</es:el>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                    </
xn:VsDataContainer>
                </
xn:ManagedElement>
            </
xn:MeContext>
            <
xn:MeContext id="LP103">
                <
xn:ManagedElement id="1">
                    <
xn:VsDataContainer id="1">
                        <
xn:attributes>
                            <
xn:vsDataType>vsDataEquipment</xn:vsDataType>
                            <
es:vsDataEquipment/>
                        </
xn:attributes>
                        <
xn:VsDataContainer id="1">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:el>80</es:el>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="2">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:el>100</es:el>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="3">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:el>90</es:el>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                    </
xn:VsDataContainer>
                </
xn:ManagedElement>
            </
xn:MeContext>
            [/
CODE
I want below Output in taxt file :-

Code:
MO	el
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP101,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	80
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP101,ManagedElement=1,Equipment=1,AntennaUnitGroup=2,AntennaNearUnit=1,RetSubUnit=1	30
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP101,ManagedElement=1,Equipment=1,AntennaUnitGroup=3,AntennaNearUnit=1,RetSubUnit=1	80
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP102,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	20
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP102,ManagedElement=1,Equipment=1,AntennaUnitGroup=2,AntennaNearUnit=1,RetSubUnit=1	100
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP102,ManagedElement=1,Equipment=1,AntennaUnitGroup=3,AntennaNearUnit=1,RetSubUnit=1	80
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP103,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	80
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP103,ManagedElement=1,Equipment=1,AntennaUnitGroup=2,AntennaNearUnit=1,RetSubUnit=1	100
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP103,ManagedElement=1,Equipment=1,AntennaUnitGroup=3,AntennaNearUnit=1,RetSubUnit=1	90

# 2  
Old 10-03-2012
try this..

Code:
awk -F '[:"<>]' -v VM="Equipment,AntennaUnitGroup,AntennaNearUnit,RetSubUnit" '{split(VM,M,",")}
/SubNetwork/{S=$3$4;}
/MeContext/{P=$3"="$4}
/ManagedElement/{K=$3"="$4;a=0}
/VsDataContainer id=/{if(T){a++;T=T","M[a]"="$4;}else{a++;T=M[a]"="$4}}
/<es:el>/{if(a==4){print S,P,K,T,$4;a=0;T=""}else{print S,P,K,T,M[4]"=1",$4;a=0;T=""}} ' OFS=, file


Last edited by pamu; 10-03-2012 at 07:01 AM..
# 3  
Old 10-03-2012
Bug

I am getting small error in Output :-

Code:
SubNetwork id=ONRM_ROOT_MO_R,MeContext id==LP101,ManagedElement id==1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1,90
SubNetwork id=ONRM_ROOT_MO_R,MeContext id==LP101,ManagedElement id==1,Equipment=2,AntennaUnitGroup=1,RetSubUnit=1,0
SubNetwork id=ONRM_ROOT_MO_R,MeContext id==LP101,ManagedElement id==1,Equipment=2,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1,60
SubNetwork id=ONRM_ROOT_MO_R,MeContext id==LP101,ManagedElement id==1,Equipment=2,AntennaUnitGroup=1,RetSubUnit=1,0
SubNetwork id=ONRM_ROOT_MO_R,MeContext id==LP101,ManagedElement id==1,Equipment=3,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1,80
SubNetwork id=ONRM_ROOT_MO_R,MeContext id==LP101,ManagedElement id==1,Equipment=2,AntennaUnitGroup=1,RetSubUnit=1,0

I want below Output

Code:
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP101,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	90
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP101,ManagedElement=1,Equipment=1,AntennaUnitGroup=2,AntennaNearUnit=1,RetSubUnit=1	60
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP101,ManagedElement=1,Equipment=1,AntennaUnitGroup=3,AntennaNearUnit=1,RetSubUnit=1	80

Thanks a lot for your time

Last edited by asavaliya; 10-03-2012 at 07:20 PM..
# 4  
Old 10-04-2012
something like this..
Code:
$awk -F '[:"<>]' -v VM="Equipment,AntennaUnitGroup,AntennaNearUnit,RetSubUnit" '{split(VM,M,",")}
/SubNetwork/{gsub(" id=","=",$0);S=$3$4;}
/MeContext/{gsub(" id=","=",$0);P=$3$4}
/ManagedElement/{gsub(" id=","=",$0);K=$3$4;a=0}
/VsDataContainer id=/{if(T){a++;T=T","M[a]"="$4;}else{a++;T=M[a]"="$4}}
/<es:el>/{if(a==4){print S,P,K,T"\t"$4;a=0;T=""}else{print S,P,K,T,M[4]"=1""\t"$4;a=0;T=""}} ' OFS=, file

SubNetwork=ONRM_ROOT_MO_R,MeContext=LP101,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1        80
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP101,ManagedElement=1,Equipment=2,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1        30
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP101,ManagedElement=1,Equipment=3,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1        80
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP102,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1        20
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP102,ManagedElement=1,Equipment=2,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1        100
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP102,ManagedElement=1,Equipment=3,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1        80
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP103,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1        80
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP103,ManagedElement=1,Equipment=2,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1        100
SubNetwork=ONRM_ROOT_MO_R,MeContext=LP103,ManagedElement=1,Equipment=3,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1        90

# 5  
Old 10-04-2012
Thanks a lot men its great and heads off to you Sir,

still getting small data swap issue..here i have post for two different data type

One have LP106 have two "et" output and LP107 have "et" one output

I have change el=et

PHP Code:
<xn:MeContext id="LP106">
                <
xn:ManagedElement id="1">
                    <
xn:VsDataContainer id="1">
                        <
xn:attributes>
                            <
xn:vsDataType>vsDataEquipment</xn:vsDataType>
                            <
es:vsDataEquipment/>
                        </
xn:attributes>
                        <
xn:VsDataContainer id="1">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:et>90</es:et>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                            <
xn:VsDataContainer id="2">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:et>0</es:et>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="2">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:et>60</es:et>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                            <
xn:VsDataContainer id="2">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:et>0</es:et>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="3">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:et>80</es:et>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                            <
xn:VsDataContainer id="2">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:et>0</es:et>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                    </
xn:VsDataContainer>
                </
xn:ManagedElement>
            </
xn:MeContext>
            <
xn:MeContext id="LP107">
                <
xn:ManagedElement id="1">
                    <
xn:VsDataContainer id="1">
                        <
xn:attributes>
                            <
xn:vsDataType>vsDataEquipment</xn:vsDataType>
                            <
es:vsDataEquipment/>
                        </
xn:attributes>
                        <
xn:VsDataContainer id="1">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:et>40</es:et>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="2">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:et>40</es:et>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                        <
xn:VsDataContainer id="3">
                            <
xn:attributes>
                                <
xn:vsDataType>vsDataAntennaUnitGroup</xn:vsDataType>
                                <
es:vsDataAntennaUnitGroup/>
                            </
xn:attributes>
                            <
xn:VsDataContainer id="1">
                                <
xn:attributes>
                                    <
xn:vsDataType>vsDataAntennaNearUnit</xn:vsDataType>
                                    <
es:vsDataAntennaNearUnit/>
                                </
xn:attributes>
                                <
xn:VsDataContainer id="1">
                                    <
xn:attributes>
                                    <
xn:vsDataType>vsDataRetSubUnit</xn:vsDataType>
                                    <
es:vsDataRetSubUnit>
                                    <
es:et>70</es:et>
                                    </
es:vsDataRetSubUnit>
                                    </
xn:attributes>
                                </
xn:VsDataContainer>
                            </
xn:VsDataContainer>
                        </
xn:VsDataContainer>
                    </
xn:VsDataContainer>
                </
xn:ManagedElement>
            </
xn:MeContext

I need below Output :--

Code:
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	90
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=2,RetSubUnit=1	0
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=2,AntennaNearUnit=1,RetSubUnit=1	80
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=2,AntennaNearUnit=2,RetSubUnit=1	0
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=3,AntennaNearUnit=1,RetSubUnit=1	60
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=3,AntennaNearUnit=2,RetSubUnit=1	0
MeContext=LP107,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	40
MeContext=LP107,ManagedElement=1,Equipment=1,AntennaUnitGroup=2,AntennaNearUnit=1,RetSubUnit=1	40
MeContext=LP107,ManagedElement=1,Equipment=1,AntennaUnitGroup=3,AntennaNearUnit=1,RetSubUnit=1	70

Equipment always =1 but AntennaUnitGroup will change 1 or 2 or 3 etc and AntennaNearUnit change if it have two output.

Thanks agiain for your valuable time

Last edited by asavaliya; 10-04-2012 at 03:47 PM..
# 6  
Old 10-04-2012
try this...
Code:
awk -F '[:"<>]' -v VM="Equipment,AntennaUnitGroup,AntennaNearUnit,RetSubUnit" '{split(VM,M,",")}
/MeContext/{gsub(" id=","=",$0);P=$3$4}
/ManagedElement/{gsub(" id=","=",$0);K=$3$4;a=0}
/VsDataContainer id=/{if(T){a++;T=T","M[a]"="$4;}else{a++;T=M[a]"="$4}}
/<es:et>/{if(a==4){print P,K,T"\t"$4;a=0;T=""}else{print P,K,T,M[4]"=1""\t"$4;a=0;T=""}} ' OFS=, file

Hope this helps youSmilie
# 7  
Old 10-04-2012
Still getting wrong Output :-

Code:
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	90
MeContext=LP106,ManagedElement=1,Equipment=2,AntennaUnitGroup=1,RetSubUnit=1	0
MeContext=LP106,ManagedElement=1,Equipment=2,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	60
MeContext=LP106,ManagedElement=1,Equipment=2,AntennaUnitGroup=1,RetSubUnit=1	0
MeContext=LP106,ManagedElement=1,Equipment=3,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	80
MeContext=LP106,ManagedElement=1,Equipment=2,AntennaUnitGroup=1,RetSubUnit=1	0

I want like this

Code:
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=1,RetSubUnit=1	90
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=1,AntennaNearUnit=2,RetSubUnit=1	0
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=2,AntennaNearUnit=1,RetSubUnit=1	60
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=2,AntennaNearUnit=2,RetSubUnit=1	0
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=3,AntennaNearUnit=1,RetSubUnit=1	80
MeContext=LP106,ManagedElement=1,Equipment=1,AntennaUnitGroup=3,AntennaNearUnit=2,RetSubUnit=1	0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing custom data into xml in Shell

Hi , I have data as below in a text file { 'AAA' => { 'A1' => 'a1 comment', 'A2' => 'a2 comment' }, 'BBB' => { 'B1' => 'b1 comment' }, 'CCC' => { 'C1' => 'c1 comment', 'C2' => 'c2 comment', 'C3' => 'c3 comment' 'C4' => 'c4... (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

Scripting Language for Parsing XML

Hello, I want to know which shell scripting language (like AWk, Perl or any other) is the best for parsing and editing 1) space or Comma Separated Datsets 2) XML type Datasets. (1 Reply)
Discussion started by: ajayram
1 Replies

3. Solaris

XML to Text file Parsing Using shell scripting

Hi, I want to parse an XML File using Shell Script preferably by using awk command, I/P file is : <gn:ExternalGsmCell id="016P3A"> <gn:attributes> <gn:mnc>410</gn:mnc> <gn:mcc>310</gn:mcc> <gn:lac>8016</gn:lac> ... (2 Replies)
Discussion started by: tech_frk
2 Replies

4. Shell Programming and Scripting

Parsing XML using shell script

Well, issue is i have to parse this script to get the VERSION: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleAllowMixedLocalizations</key> ... (9 Replies)
Discussion started by: zorosinister
9 Replies

5. Shell Programming and Scripting

XML to Text file Parsing Using shell scripting

Hi folks, Need some help with XML to text file parsing , the following is the content of the XML File. <xn:SubNetwork id="SNJNPRZDCR0R03"> <xn:MeContext id="PRSJU0005"> <xn:VsDataContainer id="PRSJU0005"> <xn:attributes> ... (6 Replies)
Discussion started by: tech_frk
6 Replies

6. Shell Programming and Scripting

XML parsing using shell script

I have a xml file like this <bul:collectionStrategy name="strategy1"> <bul:collectionTemplateGroup name="15min group"/> <bul:collectionTemplateGroup name="hourly group"/> </bul:collectionStrategy> <bul:CollectionTemplateGroup name="hourly group" > ... (2 Replies)
Discussion started by: LavanyaP
2 Replies

7. Shell Programming and Scripting

Shell script for XML code parsing.

Please help me to create a shell script that can parse the below XML and send a string back adding all XML values.:) <RequestBillsRsp... (1 Reply)
Discussion started by: xtatic
1 Replies

8. Shell Programming and Scripting

XML parsing in a shell script.

Below is a XML I have... <?xml version="1.0" encoding="UTF-8" ?> <component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:XXXXX-www-Install-Manifest manifest.xsd" xmlns="urn:qqqqq-Install-Manifest" name="OM" ... (1 Reply)
Discussion started by: dashok.83
1 Replies

9. Shell Programming and Scripting

Parsing XML using Shell Script

Hello, I'm a starting shell scripter and no Perl knowledge. I've trying to do this for a while: I want to parse an XML file and get certain data out of it and write that data into a CSV file, all this using Shell Scripting (in Bash). Or Perl without any XML Parser/Interpreter (if possible). ... (1 Reply)
Discussion started by: Kage Musha
1 Replies

10. Shell Programming and Scripting

XML parsing through shell scritps

Hi, Am new to scripting. :) Am trying to figure out whether can i use bash scripting to parse an xml file. Parsing is not just pulling out information according to the pattern but its more of a generic parsing. I should identify the xml hierarchy and pull out information accordingly. It's not a... (2 Replies)
Discussion started by: karthikvela
2 Replies
Login or Register to Ask a Question