![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
gawk '{print "\047"$11"\047"}'
|
|
#3
|
|||
|
|||
|
Thanks
Worked a treat. So simple, yet SO invaluable ....
tenakha |
|
#4
|
||||
|
||||
|
Another way:
Code:
gawk -v Q="'" '/populateNode/ {print "insert into thetable (username) values (" Q $11 Q ");"}' logfile.txt
|
||||
| Google The UNIX and Linux Forums |