AWK Script Execution!
vgersh99,
Since you gave the input as a text file, the output that you got was correct. Instead of using the text file, I used the csv file as under :
pj.csv file
---------
"Store Number", "Quarter 1 Sales", "Quarter 2 Sales", "Quarter 3 Sales", "Quarter 4 Sales"
"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%"
pj.awk file
----------
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>"}
Script Execution Command
-------------------------
nawk -v node=whatever -f pj.awk pj.csv
Output :
--------
<whateverXML>
<whatever>
</whatever>
<whatever>
<"Store>"1",</"Store>
<Number",>"35%",</Number",>
<"Quarter>"29%",</"Quarter>
<1>"59%",</1>
<Sales",>"42%"</Sales",>
</whatever>
<whatever>
<"Store>"2",</"Store>
<Number",>"61%",</Number",>
<"Quarter>"37%",</"Quarter>
<1>"34%",</1>
<Sales",>"86%"</Sales",>
</whatever>
<whatever>
<"Store>"3",</"Store>
<Number",>"68%",</Number",>
<"Quarter>"47%",</"Quarter>
<1>"62%",</1>
<Sales",>"18%"</Sales",>
</whatever>
<whatever>
<"Store>"4",</"Store>
<Number",>"78%",</Number",>
<"Quarter>"83%",</"Quarter>
<1>"91%",</1>
<Sales",>"78%"</Sales",>
</whatever>
<whatever>
<"Store>"5",</"Store>
<Number",>"53%",</Number",>
<"Quarter>"44%",</"Quarter>
<1>"67%",</1>
<Sales",>"56%"</Sales",>
</whatever>
</whateverXML>
Also, please could you explain me the steps, Sir, so I can understand better.
Thanks once again for your help.
pjanakir