Sponsored Content
Top Forums Shell Programming and Scripting converting specific XML file to CSV Post 302475707 by ctsgnb on Monday 29th of November 2010 03:30:11 PM
Old 11-29-2010
egrep -ve '<filedata|</*replica|<daos' in | sed 's/^<cutoff interval="//;s:/>:>/:;s/="/>/g;s/"/</g;s/<[^>]*>/#/g' | grep -v '^#*$' | xargs -n3 echo | sed 's/[#]*[ ]*#/#/g' >output

Code:
# cat in
<filedata notesversion="8" odsversion="51" logged="yes" backup="no" id="C125742C:0038C006" iid="7630E56A:ADB4562F" link="1" dboptions="8192,4849664,17276934,0">
<replica id="41256605:0048070F" flags="72" count="1">
<cutoff interval="90">20100811T010253,56+02</cutoff>
</replica>
<path>/base/base01/mail/mail-20/valerie_deshuissard.nsf</path>
<name>valerie_deshuissard.nsf</name>
<title>Valerie DESHUISSARD</title>
<template></template>
<inheritedtemplate>M0170DIT</inheritedtemplate>
<category>M5;w230;W230;F250;PDPI2</category>
<size current="129325927" max="0" usage="49429504"/>
<quota limit="0" warning="0"/>
<created>20080415T121951,74+02</created>
<lastcompact>20101119T182500,73+01</lastcompact>
<unread marks="yes" replicate="never"/>
<daos enabled="readwrite" objects="107" bytes="78994279" lastsync="20101126T151637,20+01"/>
</filedata>
# egrep -ve '<filedata|</*replica|<daos' in | sed 's/^<cutoff interval="//;s:/>:>/:;s/="/>/g;s/"/</g;s/<[^>]*>/#/g' | grep -v '^#*$' | xargs -n3 echo | sed 's/[#]*[ ]*#/#/g'
90#20100811T010253,56+02#/base/base01/mail/mail-20/valerie_deshuissard.nsf#valerie_deshuissard.nsf#
#Valerie DESHUISSARD#M0170DIT#
#M5;w230;W230;F250;PDPI2#129325927#0#49429504#/#0#0#/
#20080415T121951,74+02#20101119T182500,73+01#yes#never#/
#

The output may appear truncated in more than 4 lines but it is not :

Code:
# egrep -ve '<filedata|</*replica|<daos' in | sed 's/^<cutoff interval="//;s:/>:>/:;s/="/>/g;s/"/</g;s/<[^>]*>/#/g' | grep -v '^#*$' | xargs -n3 echo | sed 's/[#]*[ ]*#/#/g' >output
# wc -l output
       4 output
# cat output
90#20100811T010253,56+02#/base/base01/mail/mail-20/valerie_deshuissard.nsf#valerie_deshuissard.nsf#
#Valerie DESHUISSARD#M0170DIT#
#M5;w230;W230;F250;PDPI2#129325927#0#49429504#/#0#0#/
#20080415T121951,74+02#20101119T182500,73+01#yes#never#/

---------- Post updated at 09:30 PM ---------- Previous update was at 09:13 PM ----------

If it doesn't fit your need, please provide a representative sample of your input as well as the expected output.

Last edited by ctsgnb; 11-29-2010 at 04:24 PM..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
ZGREP(1)						    BSD General Commands Manual 						  ZGREP(1)

NAME
zgrep, zegrep, zfgrep -- print lines matching a pattern in gzip-compressed files SYNOPSIS
zgrep [grep-flags] [--] pattern [files ...] zegrep [grep-flags] [--] pattern [file ...] zfgrep [grep-flags] [--] pattern [file ...] DESCRIPTION
zgrep runs grep(1) on files or stdin, if no files argument is given, after decompressing them with zcat(1). The grep-flags and pattern arguments are passed on to grep(1). If an -e flag is found in the grep-flags, zgrep will not look for a pattern argument. zegrep calls egrep(1), while zfgrep calls fgrep(1). EXIT STATUS
In case of missing arguments or missing pattern, 1 will be returned, otherwise 0. SEE ALSO
egrep(1), fgrep(1), grep(1), gzip(1), zcat(1) AUTHORS
Thomas Klausner <wiz@NetBSD.org> BSD
December 28, 2003 BSD
All times are GMT -4. The time now is 04:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy