Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert with mysql

Status
Not open for further replies.

nomanoma

Programmer
Apr 6, 2006
24
BA
Please..how can I create command insert in shell script I have this code..but I do have problems with '.

I have this:
awk '{printf("INSERT INTO akcije (date, time, target1, target, action) VALUES ('%s','%s','%s','%s','%s');\n",substr($0,0,6),substr($0,8,17),substr($0,25,8),substr($0,33,6),substr($0,48,11));}' ca > CAndA.sq

result is: from CAndA.sq file:
..
...
INSERT INTO akcije (date, time, target1, target, action) VALUES (20060524,145222,5431,876,west);
...
.

which is not good command for mysql it needs to be like this:

INSERT INTO akcije (date, time, target1, target, action) VALUES ('20060524','145222','5431','876','west');

how can I show those ''...

Thanks..
 
Here's one way: put the single quote in a variable using octal notation in the BEGIN routine, then use that variable in your printf statements:

echo test|awk 'BEGIN{sq="\047"}{printf "%s%s%s\n", sq, $1, sq}'



HTH,

p5wizard
 
hmmm strange...I tryed this...this works:

sq="\047"
echo $sq

I get this sign '

but in awk code in my result file I get this:
.
..
....
INSERT INTO akcije (date, time, target1, target, action) VALUES (\04720060101\047,\047121212\047,\047test1\047,\047test2\047,\047test4\047);
....
...
..


any help..
Cheers,

 
Alternatively, put your awk script into a separate file and use awk -f so-and-so.awk ca > CAndA.sq.

Annihilannic.
 
I solved it the code is:

awk '{printf("INSERT INTO akcije ((date, time, target1, target, action) VALUES ('%s','%s','%s','%s','%s');\n","'"'"'"substr($0,0,6)"'"'"'","'"'"'"substr($0,8,17)"'"'"'","'"'"'"substr($0,25,8)"'"'"'","'"'"'"substr($0,33,6)"'"'"'","'"'"'"substr($0,48,11)"'"'"'");}' ca > CAndA.sq


Thanks everyone for beeing useful;

cheers,

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top