开发者

Convert XML to CSV-like structure

开发者 https://www.devze.com 2023-01-08 09:18 出处:网络
i have a xml data like below <Open> <ID>7171</ID> <Name>REENU</Name> <Description>CHUMMA</Description>

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 bel开发者_StackOverflowow 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


$ 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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号