Friday, July 24, 2009

Awk script to create Insert statements

#!/usr/bin/awk -f
BEGIN {
# change the record separator from newline to nothing
#RS=""
# change the field separator from whitespace to newline
#FS="n"

}
{
# print the second and third line of the file
if ($1=="") $1 = "NULL";
if ($2=="") $2 = "NULL";
if ($3=="") $3 = "NULL";
if ($4=="") $4 = "NULL";
print "insert into mytable (someno,sequance,1_id1,2_id2,3_id3)values(501," NR "," $2 "," $3 "," $4")
;"


}
END {

}

No comments: