inserting an apostrophe into awk output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting inserting an apostrophe into awk output
# 1  
Old 11-05-2007
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
# 2  
Old 11-05-2007
gawk '{print "\047"$11"\047"}'
# 3  
Old 11-05-2007
Thanks

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

tenakha Smilie
# 4  
Old 11-05-2007
Another way:
Code:
gawk -v Q="'" '/populateNode/ {print "insert into thetable (username) values (" Q $11 Q ");"}' logfile.txt

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Inserting a variable in awk script

I have file input.txt: >TX1-1 Freq 55 cattctgatgaatatttgtcctttagttgttatttgt >TX1-2 Freq 19 cattctgatgaatatttgtcctttagttgttatttgt >TX1-3 Freq 17 cattctgatgaatatttgtcctttagttgttatttgt >TX1-4 Freq 6 cattctgatgaatatttgtcctttagttgttatttgt >TX1-5 Freq 6 cattctgatgaatatttgtcctttagttgttatttgt ... (5 Replies)
Discussion started by: Xterra
5 Replies

2. UNIX for Dummies Questions & Answers

Inserting text into a file with awk or sed

Hello, I've been trying to get a script working that fetches weather-data and converts it into an .ics file. The script works so far put I'm stuck at the point where I need to add specific static data. A thorough search through the forum did not point me into the right direction. #!/bin/bash... (3 Replies)
Discussion started by: Schubi
3 Replies

3. Shell Programming and Scripting

awk/sed inserting muliple informations in one column

I'm probably sure I need to use either awk or sed judging by research but I'm not sure what exact command I have to do to do following...:wall: So this is my text file CPU 1 2 3 4 5 6 RAM 2 3 4 5 6 7 HAR 3 4 5 6 7 8 -------------- my input: Cur_CPU=10 Cur_RAM=11 Cur_HAR=13 Desired... (5 Replies)
Discussion started by: simonirang
5 Replies

4. Shell Programming and Scripting

AWK: Help inserting records between various matches

Hello, my apologizes if the title is a bit confusing. I am currently working with a series of files that have the form: 2 3 7 17 21 However, I need to insert records such that I have: 0 0 1 0 2 1 3 1 4 0 5 0 6 0 7 1 .... And so on. Currently I have the... (2 Replies)
Discussion started by: Euler2
2 Replies

5. Shell Programming and Scripting

Inserting date in unix shell with awk

Hi Friends, I have to insert date in a shell script in awk command., Shell script which i have written split on file into multiple and rename them based on some values. I want to add timestamp in the file name which is formed in after splitting the files. Dont know where am doing the mistake... (6 Replies)
Discussion started by: manish8484
6 Replies

6. UNIX for Dummies Questions & Answers

awk for inserting a variable containing single and double quotes

Hi i have to insert the below line into a specific line number of another file export MBR_CNT_PRCP_TYPE_CODES_DEL="'01','02','04','05','49','55','UNK'" I have passed the above line to a variable say ins_line. I have used below command to perform the insert awk 'NR==3{print "'"${ins_line}"'"}1'... (1 Reply)
Discussion started by: sathishteradata
1 Replies

7. Shell Programming and Scripting

How to use awk in inserting single quote

Hi Guys, Please someone help me to insert these numbers (enclosed with single quotes) to a statement using awk command. I'm having hard time of putting single quotes on these numbers. input file: 10214 68441 07205 80731 92234 55432 DESIRED OUTPUT: My ID Number='10214';... (1 Reply)
Discussion started by: pinpe
1 Replies

8. Shell Programming and Scripting

inserting and replacing lines with awk

Hello, I need to insert varying lines (i.e. these lines are an output of another script) between lines starting with certain fields. An example to make it more clear. This is the file where I wanna insert lines: (save it as "input.txt") ContrInMi_c_mir 2 10066 181014 200750... (12 Replies)
Discussion started by: tempestas
12 Replies

9. Shell Programming and Scripting

Replace apostrophe with backslash apostrophe

I'm coding using BASH and have a requirement to replace apostrophes with backslash apostrophes. For example below: I am here 'in my room' ok Would be changed to: I am here /'in my room/' ok The original text is coming from a field in a MySql database and is being used by another process that... (5 Replies)
Discussion started by: dbjock
5 Replies

10. Shell Programming and Scripting

inserting multiple lines with awk

awk '/<login-module code="com.nlayers.seneca.security.LdapLogin" flag="sufficient">/{p++} /<login-module code="com.nlayers.seneca.security.LdapLogin" flag="sufficient">/ && p==1 {$0="Mulitple lines here\n"$0}1' login-config.xml In the above awk code inside shell script, i am having problems when... (1 Reply)
Discussion started by: sunrexstar
1 Replies
Login or Register to Ask a Question