Something like this:
(use nawk or /usr/xpg4/bin/awk on Solaris)
Code:
awk 'END {
printf fmt, ++c, tab, cols, values
}
NR == 1 {
tab = $1
fmt = "REC %d: INSERT INTO %s(%s)\nVALUES\n(%s);\n"
next
}
/^REC/ && cols {
printf fmt, ++c, tab, cols, values
cols = ""
values = ""
next
}
{
$2 = $2 ~ /^[0-9]/ ? $2 : q $2 q
cols = cols ? cols "," $1 : $1
values = values ? values "," $2 : $2
}' FS=" *: *" q="'" input