Advertisement
Fromubiz

ok

Jan 14th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. Take the file simple.csv:
  2.  
  3. Jack,35,United States
  4. Jill,22,United Kingdom
  5. You can create the following xml file:
  6.  
  7. <?xml version="1.0"?>
  8. <Customers>
  9. <Customer>
  10. <Name>Jack</Name>
  11. <Age>35</Age>
  12. <Country>United States</Country>
  13. </Customer>
  14. <Customer>
  15. <Name>Jill</Name>
  16. <Age>22</Age>
  17. <Country>United Kingdom</Country>
  18. </Customer>
  19. </Customers>
  20. With the following script:
  21.  
  22. #!/bin/bash
  23. file_in="simple.csv"
  24. file_out="simple.xml"
  25. echo '<?xml version="1.0"?>' > $file_out
  26. echo '<Customers>' >> $file_out
  27. while IFS=$',' read -r -a arry
  28. do
  29. echo ' <Customer>' >> $file_out
  30. echo ' <Name>'${arry[0]}'</Name>' >> $file_out
  31. echo ' <Age>'${arry[1]}'</Age>' >> $file_out
  32. echo ' <Country>'${arry[2]}'</Country>' >> $file_out
  33. echo ' </Customer>' >> $file_out
  34. done < $file_in
  35. echo '</Customers>' >> $file_out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement