In a shell script, I am trying to convert an CVS file to Excel 2003 XML as described in this answer : https://stackoverflow.com/a/150368
The section below deals with creating the Row elements within the Table element
ROWS=`wc -l < $IN_FILE | sed 's/ //g' `
COLS=`awk -F',' '{print NF; exit}' $IN_FILE`
#for each row in turn, create the elements
for r in {1 to ${ROWS}}
do
echo "<Row>\n" >> $OUT_FILE
for c in {1 to ${COLS}}
do
echo "<Cell><Data>`sed -n '${r}p' $IN_FILE | cut -d "," -f ${c} `</Data></Cell> \n"
done
echo "</Row>\n" >> $OUT_FILE
done
echo "</Table>" >> $OUT_FILE
I am having problems because sed won't accept the line number as a variable.
I need to print just that row, pipe to a cut to extract just that col.
Also, not sure about using command substituion in the middle of an echo...
Any advise?