problem with quotes in awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with quotes in awk script
# 1  
Old 06-04-2009
problem with quotes in awk script

i have write this script:

Code:
#!/usr/bin/gawk -f

BEGIN {

strins="/usr/bin/mysql --user=user --password=pass -h localhost -D admin_test -e 'INSERT INTO test (id, perc) VALUES ('aaa',0)'"
system(strins)

}

the table test are so defined: id(varchar(10)), perc(int(10))

the error that i receive is: ERROR 1054 (42S22) at line 1: Unknown column 'aaa' in 'field list'

how i can fix this?! Smilie
# 2  
Old 06-04-2009
you have to supress single quote as \'
# 3  
Old 06-04-2009
Code:
strins="/usr/bin/mysql --user=user --password=pass -h localhost -D admin_test -e 'INSERT INTO test (id, perc) VALUES (" "'aaa'" ",0)'"

# 4  
Old 06-04-2009
Quote:
Originally Posted by vgersh99
Code:
strins="/usr/bin/mysql --user=user --password=pass -h localhost -D admin_test -e 'INSERT INTO test (id, perc) VALUES (" "'aaa'" ",0)'"

so i have the same error... Smilie

-----Post Update-----

so

Code:
strins="/usr/bin/mysql --user=user --password=pass -h localhost -D admin_test -e \'INSERT INTO test (id, perc) VALUES (\'aaa\',0)\'"

i receive two errors:
1) warning: escape sequence `\'' treated as plain `''
2) Unknown column 'aaa' in 'field list'

Smilie
# 5  
Old 06-04-2009
Quote:
Originally Posted by dogo21sob
how i can fix this?! Smilie
i will give an example
Code:
awk 'BEGIN{
 q="\047"
}
{
 print "select .... "  q "table blah" q
}' file

# 6  
Old 06-04-2009
i've tryed so:

Code:
q="\047"
strins="/usr/bin/mysql --user=user --password=K9LUCLof0KZ -h localhost -D admin_test -e" q "INSERT INTO test (id, perc) VALUES (" q "aaa" q ",0)" q ""

but the error was the same:
Unknown column 'aaa' in 'field list'

Last edited by dogo21sob; 06-04-2009 at 11:40 AM..
# 7  
Old 06-04-2009
print out strins variable, then use it to run manually on the command line. what did you see.?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using quotes in awk

Hello, i had a problem running a script , and after investigation found its all to do with the quotes: cat file1 line1 val1 val2 line2 val1 val2 line3 val1 val2 awk 'BEGIN {RS="\n\n"; FS="\n";} {print $1 $2}' file1 This gives me the wrong output: (5 Replies)
Discussion started by: andy391791
5 Replies

2. Shell Programming and Scripting

awk - Print where value is in quotes

Hi All, I have input data like follows: "1234"|"ABC" "1234"|"CBA" "1222"|"ZZZ" I am trying to awk print all records where Col1 = "1234". Below is the code I have so far: Var1=1 Var2=1234 awk -F "|" "$ ${Var1} == "\"${Var2}\"" { print; }' inputfile However when the AWK... (2 Replies)
Discussion started by: RichZR
2 Replies

3. Shell Programming and Scripting

awk problem with quotes

can someone help me with this. i keep getting errors: var1="MaxClients" var2="java|could not.*problem found|panic() failure seen|aborting " awk 'NR>=1&&NR<=10 && /'${var1}'/ && !/'${var2}'/ {++c}c==3{o=$0 RS $0 RS $0; print o; c=0}' log when i run the above, i keep getting: awk:... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

awk without quotes

I want to execute awk command without quotes. who am i | awk {'print $2'} above code should be something like: who am i | awk {print $2} Why such weird requirement? Im assigning command to a variable, hence i need to escape the quotes. e.g: x='who am i | awk {\'print $2\'}' I want... (11 Replies)
Discussion started by: Arun_Linux
11 Replies

5. Shell Programming and Scripting

Having a terrible problem with quotes/single quotes!

Hello. I'm trying to write a bash script that uses GNU screen and have hit a brick wall that has cost me many hours... (I'm sure it has something to do with quoting/globbing, which is why I post it here) I can make a script that does the following just fine: test.sh: #!/bin/bash # make... (2 Replies)
Discussion started by: jondecker76
2 Replies

6. Shell Programming and Scripting

Using double quotes in awk

Hi I read somewhere that when using double quotes in awk; variables gets expanded else it doesn't. So I tried to use the double quotes inside an awk statement as below: from_instance_trans=`awk "/INPUT =\"$frm_inst\"/,/<\/TRANSFORMATION>/" $xml_object | grep -w "<TRANSFIELD" | awk... (9 Replies)
Discussion started by: dips_ag
9 Replies

7. Shell Programming and Scripting

problem with echo inserting single quotes

Consider the following script: #!/bin/bash exclude='Archive PST,SystemState' IFS=$"," rsyncExclusions=$(for exclude in ${exclude}; do echo -n -e --exclude=\"${exclude}\"\ ; done) unset IFS echo rsync $rsyncExclusions test rsync -avh --delete --delete-excluded "$rsyncExclusions"... (7 Replies)
Discussion started by: jelloir
7 Replies

8. Shell Programming and Scripting

quotes using awk

i want to print the statement below using awk,but i am unable to get the quotes ("22345",1,"Thank you"); How can i do this (5 Replies)
Discussion started by: tomjones
5 Replies

9. Shell Programming and Scripting

Problem renaming a file with single quotes

Hi, I am trying to create a script which validates the incoming source files. The script has File name Pattern as Argument. The First part of the script validates if there are any files available if then echo "\n Files are available to process \n" else echo "\n File does not... (9 Replies)
Discussion started by: dsshishya
9 Replies

10. Shell Programming and Scripting

problem with single quotes in a string and findbug

I'm having trouble manipulating a string that contains single quotes (') in it. I'm writing a ksh script to parse in a few queries from a config file, such as this: findbug \(\(Project 'in' "Deployment,HDRCI,LHS,LSS,WUCI" '&&' Status 'in' "N" '&&' New_on 'lessthan' "070107" \)\) '&&' \(Class... (9 Replies)
Discussion started by: bob122480
9 Replies
Login or Register to Ask a Question