Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Take the file simple.csv:
- Jack,35,United States
- Jill,22,United Kingdom
- You can create the following xml file:
- <?xml version="1.0"?>
- <Customers>
- <Customer>
- <Name>Jack</Name>
- <Age>35</Age>
- <Country>United States</Country>
- </Customer>
- <Customer>
- <Name>Jill</Name>
- <Age>22</Age>
- <Country>United Kingdom</Country>
- </Customer>
- </Customers>
- With the following script:
- #!/bin/bash
- file_in="simple.csv"
- file_out="simple.xml"
- echo '<?xml version="1.0"?>' > $file_out
- echo '<Customers>' >> $file_out
- while IFS=$',' read -r -a arry
- do
- echo ' <Customer>' >> $file_out
- echo ' <Name>'${arry[0]}'</Name>' >> $file_out
- echo ' <Age>'${arry[1]}'</Age>' >> $file_out
- echo ' <Country>'${arry[2]}'</Country>' >> $file_out
- echo ' </Customer>' >> $file_out
- done < $file_in
- echo '</Customers>' >> $file_out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement