tags:

views:

57

answers:

1

Hi i have a xml data like below

<Open>
        <ID>7171</ID>
        <Name>REENU</Name>
        <Description>CHUMMA</Description>
        <Active>1</Active>
        <Users>1</Users>
</Open>

<Open>
        <ID>7172</ID>
        <Name>BEENU</Name>
        <Description>CHUMMA</Description>
        <Active>1</Active>
        <Users>1</Users>
</Open>

<Open>
        <ID>7173</ID>
        <Name>CEENU</Name>
        <Description>CHUMMA</Description>
        <Active>1</Active>
        <Users>1</Users>
</Open>

<Open>
        <ID>7174</ID>
        <Name>DEENU</Name>
        <Description>CHUMMA</Description>
        <Active>1</Active>
        <Users>1</Users>
</Open>

<Open>
        <ID>7175</ID>
        <Name>GEENU</Name>
        <Description>CHUMMA</Description>
        <Active>1</Active>
        <Users>1</Users>
</Open>

i want to convert into csv using UNIX commands like below using unix commands basically i want to print the middle value of the xml tag

Open,7171,REENU,CHUMMA,1,1
Open,7172,BEENU,CHUMMA,1,1
Open,7173,CEENU,CHUMMA,1,1
Open,7174,DEENU,CHUMMA,1,1
Open,7175,GEENU,CHUMMA,1,1
A: 
$ nawk '/<\/Open>/{print ""}{gsub(/<.[^>]*>/,"");printf "%s, ",$0} ' file | sed -e 's/^[ \t,]*/Open,/' -e 's/,[ \t]*/,/g' -e 's/,$//'
Open,7171,REENU,CHUMMA,1,1
Open,7172,BEENU,CHUMMA,1,1
Open,7173,CEENU,CHUMMA,1,1
Open,7174,DEENU,CHUMMA,1,1
ghostdog74