converting specific XML file to CSV


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting converting specific XML file to CSV
# 22  
Old 11-30-2010
Code:
egrep -ve '^[:blank:]*$|xml version|<files xmlns' in | sed 's/^[ ]*//;s/^<filedata/|&/;s:/>:>/:;s/="/>/g;s/"/</g;s/<[^>]*>/#/g' | tr '\n|' ' \n' | sed 's/[ ]*[#]*#/#/g;s/#*#/#/g'

?
This User Gave Thanks to ctsgnb For This Post:
# 23  
Old 11-30-2010
Computer

SmilieSmilieSmilie
It seems to be perfect.

I will test differents types of input files.

then i will put it in a script over many lines to have it more readable.

well many many thanks to everybody who help me

Christian
# 24  
Old 11-30-2010
If you have Perl, then you could do something like this -

Code:
$
$
$ cat f44.xml
<?xml version="1.0" encoding="UTF-8" ?>
<files xmlns="http://www.lotus.com/dxl/console">
<filedata notesversion="8" odsversion="51" logged="yes" >
<cutoff interval="90">20100811T010253,56+02</cutoff>
<path>/base/base01/mail/mail-20/valerie_deshuissard.nsf</path>
</filedata>
<filedata notesversion="8" odsversion="51" logged="yes" >
<cutoff interval="90">20100811T010231,02+02</cutoff>
<path>/base/base01/mail/mail-20/laurent_abello.nsf</path>
</filedata>
$
$
$ perl -lne 'BEGIN {undef $/}
             while (/<filedata.*?="(.*?)".*?="(.*?)".*?="(.*?)".*?="(.*?)">(.*?)<.*?>.*?>(.*?)<.*?<\/filedata>/sg) {
               print "#$1#$2#$3#$4#$5#$6#"}
            ' f44.xml
#8#51#yes#90#20100811T010253,56+02#/base/base01/mail/mail-20/valerie_deshuissard.nsf#
#8#51#yes#90#20100811T010231,02+02#/base/base01/mail/mail-20/laurent_abello.nsf#
$

$

tyler_durden
# 25  
Old 12-01-2010
Hammer & Screwdriver

Thanks for you help , but i'm not using PERL at all.
In my job we used shell script on AIx machine and we must continue for maintenance reason on the same way

regards
Christian
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting XML to CSV

Hello, For i while i have been using XMLStarlet to convert several XML files to CSV files. So far this always went fine. Today however i got a new XML format however but i cannot find out how to get the data i need. Below is part of the code where it shows the different format. What... (10 Replies)
Discussion started by: SDohmen
10 Replies

2. UNIX for Beginners Questions & Answers

Data extraction and converting into .csv file.

Hi All, I have a data file and need to extract and convert it into csv format: 1) Read and extract the line containing string ending with "----" (file sample_linebyline.txt file) and to make a .csv file from this. 2) To read the flat file flatfile_sample.txt which consists of similar data (... (9 Replies)
Discussion started by: abhi_123
9 Replies

3. Shell Programming and Scripting

Converting rows to columns in csv file

Hi, I have a requirement to convert rows into columns. data looks like: c1,c2,c3,.. r1,r2,r3,.. p1,p2,p3,.. and so on.. output shud be like this: c1,r1,p1,.. c2,r2,p2,.. c3,r3,p3,.. Thanks in advance, (12 Replies)
Discussion started by: Divya1987
12 Replies

4. Shell Programming and Scripting

Help with converting XML to Flat file

Hi Friends, I want to convert a XML file to flat file. Sample I/p: <?xml version='1.0' encoding='UTF-8' ?> <DataFile xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' contactCount='4999' date='2012-04-14' time='22:00:14' xsi:noNamespaceSchemaLocation='gen .xsd'> <Contact... (3 Replies)
Discussion started by: karumudi7
3 Replies

5. Shell Programming and Scripting

need to save the space when converting to CSV file

Hi, I have a text file with the following format. Some of the fields are blank. 1234 3456 23 45464 327837283232 343434 5654353 34 34343 3434345 434242 .... .... .... I need to convert this file to a CSV file, like 1234, ,23, ... (3 Replies)
Discussion started by: wintersnow2011
3 Replies

6. Shell Programming and Scripting

Converting specific Excel file tabs to CSV in Python

Hi list, This is probably something really simple, but I am not particularly familiar with Python so I thought I would ask as I know that python has an excel module. I have an excel document with multiple tabs of data and graphs. One of the tabs is just data which I require to have dumped to... (8 Replies)
Discussion started by: landossa
8 Replies

7. Shell Programming and Scripting

convert huge .xml file in .csv with specific column.

I have huge xml file in server and i want to convert it to .csv with specific column ... i have search in blog but i didn't get any usefully command. Thanks in advance (1 Reply)
Discussion started by: pareshkp
1 Replies

8. Shell Programming and Scripting

Converting a flat file in XML

Hello Friends, I am new to UNIX shell scripting. Using bash....Could you please help me in converting a flat file into an XML style output file. Flat file: (Input File entries looks like this) John Miller: 617-569-7996:15 Bunting lane, staten Island, NY: 10/21/79: 60600 The... (4 Replies)
Discussion started by: humkhn
4 Replies

9. Shell Programming and Scripting

XML to CSV specific

Hi , Please any one to help on ,extract this xml code into csv columns list. <SOURCEFIELD BUSINESSNAME ="" DATATYPE ="date" DESCRIPTION ="" FIELDNUMBER ="1" FIELDPROPERTY ="0" FIELDTYPE ="ELEMITEM" HIDDEN ="NO" KEYTYPE ="NOT A KEY" LENGTH ="19" LEVEL ="0" NAME ="BUSINESS_DATE"... (4 Replies)
Discussion started by: mohan705
4 Replies

10. Shell Programming and Scripting

Converting txt file in csv

HI All, I have a text file memory.txt which has following values. Average: 822387 7346605 89.93 288845 4176593 2044589 51883 2.47 7600 i want to convert this file in csv format and i am using following command to do it. sed s/_/\./g <... (3 Replies)
Discussion started by: mkashif
3 Replies
Login or Register to Ask a Question