inserting an apostrophe into awk output

hello,

I have a simple awk script thus:

egrep populateNode logfile.txt | gawk '{print $11}'

This gives me a list of usernames.

I want to pipe the above command into another command that will surround each username with an SQL insert statement:

insert into thetable (username) values ('username');

I'm trying to get awk to do this:

egrep populateNode logfile.txt | gawk '{print "insert into thetable (username) values ('" $11 "');"}'

but the apostophes around the username are killing the awk command :frowning:

How can I output apostrophes within the "" ?? I've tried using \' - doesn't work ..

I'm using gawk on cygwin.

Regards

Tenakha

gawk '{print "\047"$11"\047"}'

Worked a treat. So simple, yet SO invaluable ....

tenakha :slight_smile:

Another way:

gawk -v Q="'" '/populateNode/ {print "insert into thetable (username) values (" Q $11 Q ");"}' logfile.txt

Jean-Pierre.