
passing shell vars to gawk
Hello,
I've written a script, using bash and gawk, that will convert csv files to html tables. I'm
have trouble. Here is the script:
****
#! /bin/bash
#awk script to create HTML tables from CSV files
#usage table <csv-file> <caption>
CSV=$1
CAPTION=$2
awk -F, '
BEGIN {
print "<table border cellspacing=0 cellpadding=5>"
print "<caption>" $CAPTION"</caption>"
}
{
x=1
print"<tr>"
while ( x <= NF ) {
if ( NR ==1) print "\t "<th>" $x "<th>"
else print "\t <td>" $x "<td>"
++x
}
print "</tr>"
Quote:
}
END {
print "</table>"
Quote:
}' $CSV
*****
My problem is that I cannot transfer the $2 bash argument to the awk
script. I've tried:
print "<caption>" ARGV[2] "</caption>"
awk -F -v CAPTION="$CAPTION"
awk -F -v CAPTION=$CAPTION
BEGIN{
caption="'"$CAPTION"'"
Nothing seems to work. I know it's something simple that I don't yet
know but I can't figure out what it is. Will someone help me out?
Thanks,
--
Neil Watson
Network Administrator
www.watson-wilson.ca