converting specific XML file to CSV


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting converting specific XML file to CSV
# 1  
Old 11-25-2010
converting specific XML file to CSV

Hi,

i would convert the following XML file :
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<files xmlns="http://www.lotus.com/dxl/console">
 <filedata notesversion="6" odsversion="43" logged="yes" backup="no" id="C12577E6:004B0DA3" iid="C12577E6:004B0DA8" link="1" dboptions="0,524288,0,0">
  <replica id="C12577E6:004B0DA3" flags="64" count="1">
   <cutoff interval="90">20100622T102416,65+02</cutoff>
  </replica>
  <path>/base/base01/appli/appli-01/natachat/postetravail.nsf</path>
  <name>postetravail.nsf</name>
  <title>Poste de Travail</title>
  <template></template>
  <inheritedtemplate>m_natachat_postetrav_17-3-0</inheritedtemplate>
  <category>toto</category>
  <size current="8650752" max="0" usage="0"/>
  <quota limit="0" warning="0" />
  <created>20101125T143946,91+01</created>
  <lastfixup>20101125T145142,38+01</lastfixup>
  <unread marks="yes" replicate="never"/>
 </filedata>
 <filedata

and so on

so every field between double quote contained in a XML statement
as in :
Code:
<size current="8650752" max="0" usage="0"/>

and the complete data contained in the XML statement as:
Code:
<name>postetravail.nsf</name>

i tried to figure all necessary data in bold

all these fields separated by #

and end of line after each </filedata> paragraph

and for sure without the header xml version.....

i began to try with this kind of shell :
Code:
sed -n '/^<filedata notesversion/h;{/}/!={H;g;s/\n/;/;s/\t//gp;d}'

but without success

if somebody can help me ?

i continue to search

thanks in advance

Last edited by Scott; 11-26-2010 at 07:01 AM.. Reason: Code tags
# 2  
Old 11-25-2010
Quote:
expected output?
# 3  
Old 11-25-2010
Hi,

all data in bold separated by #

like:
Code:
20101125T143946,91+01#20101125T145142,38+01#yes#never#

and so on

regards
Christian

Last edited by Scott; 11-26-2010 at 07:01 AM..
# 4  
Old 11-25-2010
I'm not sure if I understood what you need but if it's all data between " try this:
Code:
$ awk -vRS=\=\" -F\" 'NR>4{print $1}' ORS="#" file
6#43#yes#no#C12577E6:004B0DA3#C12577E6:004B0DA8#1#0,524288,0,0#C12577E6:004B0DA3#64#1#90#8650752#0#0#0#0#yes#never#

# 5  
Old 11-26-2010
Thanks ,

this is what i need + the data between xml statement like :
Code:
<title>Poste de Travail</title>

result :
Code:
Poste de Travail

i will test your post

regards
Christian

Last edited by Scott; 11-26-2010 at 07:02 AM..
# 6  
Old 11-26-2010
Code:
sed 's/<[^>]*>//g' input >output

Code:
# echo "<title>Poste de Travail</title>"
<title>Poste de Travail</title>
# echo "<title>Poste de Travail</title>" | sed 's/<[^>]*>//g'
Poste de Travail

But that code will remove all mark like <.*> (whatever .* could be)
If you want to remove only "title" mark
then
Code:
sed 's/<[^>]*title>//g' input >output


Last edited by ctsgnb; 11-26-2010 at 05:01 AM..
# 7  
Old 11-26-2010
Thanks ,

i doesn't work exactly as i expect , let's me resume :

the input file is :
Code:
<?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>

and i expect exactly on output:
Code:
first line :
8#51#yes#90#20100811T010253,56+02#/base/base01/mail/mail-20/valerie_deshuissard.nsf#

second line:
8#51#yes#90#20100811T010231,02+02#/base/base01/mail/mail-20/laurent_abello.nsf#

etc.

so
i don't want to keep the header :
Code:
<?xml version="1.0" encoding="UTF-8" ?>

<files xmlns="http://www.lotus.com/dxl/console">

and
i want to keep on one line all data extracted between <filedata
and
Code:
</filedata>

i know this is quite complicated but i'm too basic shell writer to succeed.


thanks again to help me
regards
Christian

Last edited by Scott; 11-26-2010 at 07:03 AM.. Reason: Code tags
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