create SQL-statements from textfile with awk

create SQL-statements from textfile with awk

1
$ $ awk \'{printf \"select * from table where id = %c%s%c;\\n\",39,$1,39; }\' inputfile.txt

inputfile.txt is a space-separated textfile, 1st column contains the items (id) I want to put into my SQL statement.

39 = charactercode for single tick \’

1
1 = first column

If inputfile.txt is a CSV-file separated by \”,\” use FS= to define your own field-separator:

1
awk \'BEGIN {FS=\",\"; }{printf \"select * from table where id = %c%s%c;\\n\",39,$1,39; }\' inputfile.txt

\"commandlinefu.com\"

by David Winterbottom (codeinthehole.com)

\"\"

\"\"

\"\"

URL: http://feedproxy.google.com/~r/Command-line-fu/~3/lz9uEhVxEEk/create-sql-statements-from-textfile-with-awk

About Amit Agarwal