ksh CSV to XML file (noob tier)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh CSV to XML file (noob tier)
# 1  
Old 06-18-2013
ksh CSV to XML file (noob tier)

Hey all,

I'm very new to shell scripting and would love some help. I have been messing around with KSH at my job, and have been tasked with generating an XML file from multiple CSV files. However, I barely even understand the syntax for for loops! Output should be something along the lines of

Code:
<section name="Query1">
<entry name="DocumentType">first field from first CSV file</entry>
<entry name=Name1">second field from first CSV file</entry>
<entry name="Value1">first field from second CSV file</entry>
...
<entry name=NameN">N+1th field from first CSV file</entry>
<entry name="ValueN">Nth field from second CSV file</entry>
</section>

This will go on until a newline, at which point the process will repeat. Can anyone point me in the direction of a guide that will explain the process? Really, it's the whole escaping characters thing that's killing me, because it makes any code I look at seem foreign. The guy I'm working on this under hasn't provided the second .CSV file yet, so I'm not even 100% sure of the syntax. Also, the first .CSV file contains a lot of empty fields, I want to make sure I just skip over those properly. I realize that this is a very n00bish request, since I don't even have pseudocode yet, just trying to get a handle on how to handle delimiters and what not. Thanks in advance for any help.

Last edited by radoulov; 06-18-2013 at 12:34 PM..
# 2  
Old 06-18-2013
I would suggest using paste and read each field using a while loop:
Code:
paste file1.csv file2.csv | while read f1 f2 f3 f4
do
   ...
done

# 3  
Old 06-18-2013
Interesting. I never even knew that command existed. Seems like it should be able to do what I want; thanks, gonna play around a bit.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create a XML file for each row from the csv file

I have a CSV file that looks like this: File,Name,birthdate,Amount File1.xml,Name1,01.02.19,1000 File2.xml,Name2 01.02.20,1000 File3.xml,Name3,01.02.21,1000 I need it to turn it into an XML file for each row, My ultimate goal is for the File1.xml look like this: <?xml version="1.0"... (5 Replies)
Discussion started by: lxdorney
5 Replies

2. Shell Programming and Scripting

Splitting CSV into variables then to XML file

I have a text file that looks like this: FIELD1, FIELD2, THIS IS FIELD3, FIELD4 FIELD1, FIELD2, THIS IS FIELD3, FIELD4 FIELD1, FIELD2, THIS IS FIELD3, FIELD4 I need it to turn it into an XML file to run against a custom application. My ultimate goal is for it to look like... (15 Replies)
Discussion started by: jeffs42885
15 Replies

3. UNIX for Advanced & Expert Users

Convert CSV file to nested XML file using UNIX/PERL?

we have a CSV which i need to convert to XML using Perl or Unix shell scripting. I was able to build this XML in oracle database. However, SQL/XML query is running for long time. Hence, I'm considering to write a Perl or shell script to generate this XML file. Basically need to build this XML... (3 Replies)
Discussion started by: laknar
3 Replies

4. Shell Programming and Scripting

Compare 2 csv files in ksh and o/p the difference in a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 The... (7 Replies)
Discussion started by: Naresh101
7 Replies

5. Shell Programming and Scripting

Extract data from XML file and write in CSV file

Hi friend i have input as following XML file <?xml version="1.0"?> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"> <BkToCstmrDbtCdtNtfctn> <GrpHdr><MsgId>LBP-RDJ-TE000000-130042430010001001</MsgId><CreDtTm>2013-01-04T03:21:30</CreDtTm></GrpHdr>... (3 Replies)
Discussion started by: mohan sharma
3 Replies

6. Shell Programming and Scripting

Need help to change values in XML using Python? noob help pls!

Hello I am a noob in XML and Python. I am trying to do this for my MSc project about a network simulation and need some help.... I want to change the values shown below: <num_crash_failures>1</num_crash_failures> −<crash_failure_entry> <freeze_at_slot>0</freeze_at_slot>... (0 Replies)
Discussion started by: erhanasd
0 Replies

7. Shell Programming and Scripting

csv file editing using KSH

I'm trying to write a shell script to extract useful fields in a csv file and copy them to a new file: the input file is as below when opened using notepad++: //////////////////////////////////////////////////////////// ZZZZZZZZZZZZZZZZZZZZZZ ,"A", , , ,24,18,0,0,42,0 , ,B, ,... (1 Reply)
Discussion started by: zekruss
1 Replies

8. Shell Programming and Scripting

converting specific XML file to CSV

Hi, i would convert the following XML file : <?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"> ... (24 Replies)
Discussion started by: Nicol
24 Replies

9. Shell Programming and Scripting

Extract data from an XML file & write into a CSV file

Hi All, I am having an XML tag like: <detail sim_ser_no_1="898407109001000090" imsi_1="452070001000090"> <security>ADM1=????</security> <security>PIN1=????</security> <security>PIN2=????</security> ... (2 Replies)
Discussion started by: ss_ss
2 Replies

10. Shell Programming and Scripting

Parse XML file into CSV with shell?

Hi, It's been a few years since college when I did stuff like this all the time. Can someone help me figure out how to best tackle this problem? I need to parse a file full of entries that look like this: <eq action="A" sectyType="0" symbol="PGR" exch="CA" curr="VEF" sess="NORM"... (7 Replies)
Discussion started by: Pcushing
7 Replies
Login or Register to Ask a Question