|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
CSV to XML
Iam pretty new to UNIX and would like to convert a CSV to an XML file using AWK scripts. Can anybody suggest a solution? My CSV file looks something like this :
Serial No Growth% Annual % Commission % Unemployed % 1 35% 29% 59% 42% 2 61% 37% 34% 86% 3 68% 47% 62% 18% 4 78% 83% 91% 78% 5 53% 44% 67% 56% |
| Sponsored Links | ||
|
|
|
#2
|
||||
|
||||
|
You mean like this?
"35%","29%","59%","42%" "61%","37%","34%","86%" "68%","47%","62%","18%" "78%","83%","91%","78%" "53%","44%","67%","56%" Otherwise it would not be CSV file. |
|
#3
|
|||
|
|||
|
CSv to XML
Yes, that's what I mean.
|
|
#4
|
|||
|
|||
|
AWK Script!
Hi photon,
Can you help me with that problem I had - converting my CSV file to XML using AWK Scripts? I need it really urgently and I need your help. Since Iam new to Unix, it is making it harder to deduce and try to understand quickly. Please help. Thanks. |
|
#5
|
||||
|
||||
|
Quote:
Code:
SerialNo Growth% Annual% Commissio% Unemployed% 1 35% 29% 59% 42% 2 61% 37% 34% 86% 3 68% 47% 62% 18% 4 78% 83% 91% 78% 5 53% 44% 67% 56% and script - pj.awk Code:
BEGIN {OFS = "\n"}
NR == 1 {for (i = 1; i <=NF; i++)
tag[i]=$i
print "<" node "XML>"}
NR != 1 {print " <" node ">"
for (i = 1; i <= NF; i++)
print " <" tag[i] ">" $i "</" tag[i] ">"
print " </" node ">"}
END {print "</" node "XML>"}nawk -v node=whatever -f pj.awk pj.txt produces: Code:
<whateverXML>
<whatever>
<SerialNo>1</SerialNo>
<Growth%>35%</Growth%>
<Annual%>29%</Annual%>
<Commissio%>59%</Commissio%>
<Unemployed%>42%</Unemployed%>
</whatever>
<whatever>
<SerialNo>2</SerialNo>
<Growth%>61%</Growth%>
<Annual%>37%</Annual%>
<Commissio%>34%</Commissio%>
<Unemployed%>86%</Unemployed%>
</whatever>
<whatever>
<SerialNo>3</SerialNo>
<Growth%>68%</Growth%>
<Annual%>47%</Annual%>
<Commissio%>62%</Commissio%>
<Unemployed%>18%</Unemployed%>
</whatever>
<whatever>
<SerialNo>4</SerialNo>
<Growth%>78%</Growth%>
<Annual%>83%</Annual%>
<Commissio%>91%</Commissio%>
<Unemployed%>78%</Unemployed%>
</whatever>
<whatever>
<SerialNo>5</SerialNo>
<Growth%>53%</Growth%>
<Annual%>44%</Annual%>
<Commissio%>67%</Commissio%>
<Unemployed%>56%</Unemployed%>
</whatever>
</whateverXML> |
|
#6
|
|||
|
|||
|
AWK Script!
vgersh99,
thanks for your help. Can you explain it step by step, so I can understand better. When I open my unix box, and say openssh servername and enter user name and password. after that how do I execute this script? Do let me know as Iam entirely new to this project. I would be very greatly indebted to you for your timely help. Thanks, pjanakir |
|
#7
|
|||
|
|||
|
CSV File!
Hi vgersh99,
Also the file that Iam sending should only be a CSV file, and not a text file. You said pj.txt, it should be pj.csv. Just to let you know about it. Thanks, pjanakir |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|