Let's begin our activity as follows:
- Open a terminal and create the data-csv-to-xml.sh script with the following contents. Then, execute the script after saving it using $ bash data-csv-to-xml.sh:
#!/bin/bash# Import template variablessource xml-parent.tplsource word.tplOUTPUT_FILE="words.xml"INPUT_FILE="words.csv"DELIMITER=','# Setup headerecho ${XML_HDR} > ${OUTPUT_FILE}echo ${SRT_CONTR} >> ${OUTPUT_FILE}# Enter contentecho ${ELM} | \sed '{:q;N;s/\n/\\n/g;t q}'| \awk \'{ print "awk \x27 BEGIN{FS=\"'${DELIMITER}'\"}{print "$0"}\x27 '${INPUT_FILE}'"}' | \ sh >> ${OUTPUT_FILE}# Append trailerecho ${END_CONTR} >> ${OUTPUT_FILE}cat ${OUTPUT_FILE}
- Examine the output, but be aware that "pretty" XML isn't necessary and in fact, ...