The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
inserting line?? anj UNIX for Dummies Questions & Answers 7 11-03-2007 09:18 AM
Inserting a carriage rtn in a sed cmd sirtrancealot Shell Programming and Scripting 6 07-14-2006 02:08 AM
Escaping apostrophe using shell script mradul_kaushik Shell Programming and Scripting 2 03-30-2006 10:06 AM
How to strip apostrophe from a file aquimby Shell Programming and Scripting 8 06-23-2005 12:04 PM
Inserting a space dbrundrett Shell Programming and Scripting 3 02-27-2004 09:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-05-2007
Registered User
 

Join Date: Nov 2007
Posts: 2
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 :-(

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

I'm using gawk on cygwin.

Regards

Tenakha
Reply With Quote
Forum Sponsor
  #2  
Old 11-05-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
gawk '{print "\047"$11"\047"}'
Reply With Quote
  #3  
Old 11-05-2007
Registered User
 

Join Date: Nov 2007
Posts: 2
Thanks

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

tenakha
Reply With Quote
  #4  
Old 11-05-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
Another way:
Code:
gawk -v Q="'" '/populateNode/ {print "insert into thetable (username) values (" Q $11 Q ");"}' logfile.txt
Jean-Pierre.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0