I'm trying to generate SQL table header from a csv file. As I had some trouble I wrote a test snippet, here's what I've got so far:
#!/bin/bash
function quote {
for i ; do
# echo "\`$i\`"
echo "\`$i\` varchar (100),\n"
done
}
quote $(head -1 Zustaendigkeit.csv | sed 's/;/ /g')
This is the csv line I use:
Netz;Strasse;PLZ_Ort;Land;Amt;Amt_Nr;PLZ;Ort
This is what I get with the above snippet:
[root@db ~]
174# ./tst.sh
`Netz` varchar (100),\n
`Strasse` varchar (100),\n
`PLZ_Ort` varchar (100),\n
`Land` varchar (100),\n
`Amt` varchar (100),\n
`Amt_Nr` varchar (100),\n
`PLZ` varchar (100),\n
` varchar (100),\n
In the last line it's missing Ort at the beginning of the line. When I use only "echo "\$i`"" which is commented in the above snippet I get this:
[root@db ~]
170# ./tst.sh
`Netz`
`Strasse`
`PLZ_Ort`
`Land`
`Amt`
`Amt_Nr`
`PLZ`
`Ort
Which is missing the last `
Hope someone has the missing link for me....
Greetz Mirco