Need to process the file using for loop
I have written below code to convert csv to xml. Here have written separate tag for each column.
In input file have column from 1 to 278. In output file need to have tag from A1 to A278,
Code :
file_in="Prepaid_plan_voucher.csv"
file_out="Prepaid_plan_voucher.xml"
echo '<?xml version="1.0"?>' > $file_out
#echo '<Customers>' >> $file_out
echo ' <TariffRecords>' >> $file_out
echo ' <Tariff>' >> $file_out
while IFS=$',' read -r -a arry
do
# echo ' <TariffRecords>' >> $file_out
# echo ' <Tariff>' >> $file_out
echo ' <A1>'${arry[0]}'</A1>' >> $file_out
echo ' <A2>'${arry[1]}'</A2>' >> $file_out
echo ' <A3>'${arry[2]}'</A3>' >> $file_out
# echo ' </TariffRecords>' >> $file_out
# echo ' </Tariff>' >> $file_out
done < $file_in
#echo '</Customers>' >> $file_out
echo ' <TariffRecords>' >> $file_out
echo ' <Tariff>' >> $file_out
Sample Input file.(this is a sample record in actual input file will contain 278 columns). If input file has two or three records, same needs to be appended in one XML file.
name,Tariff Summary,Record ID No.,Operator Name,Circle (Service Area),list
Prepaid Plan Voucher,test_All calls 2p/s,TT07PMPV0188,Ta Te,Gu,
Prepaid Plan Voucher,test_All calls 3p/s,TT07PMPV0189,Ta Te,HR,
Sample output file The above two TariffRecords, tariff will be hard coded at the beginning and end of xml file.
<TariffRecords>
<Tariff>
<A1>Prepaid Plan Voucher</A1>
<A2>test_All calls 2p/s</A2>
<A3>TT07PMPV0188</A3>
<A4>Ta Te</A4>
<A5>Gu</A5>
<A6></A6>
<Tariff>
<Tariff>
<A1>Prepaid Plan Voucher</A1>
<A2>test_All calls 3p/s</A2>
<A3>TT07PMPV0189</A3>
<A4>Ta Te</A4>
<A5>HR</A5>
<A6></A6>
<Tariff>
<TariffRecords>