Home > Archive > AWK > April 2005 > Why won't this AWK work to create SQL with Today's date?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Why won't this AWK work to create SQL with Today's date?
|
|
|
| All, I'm trying to create a sql file from a flatfile. I can create the
file just finebut when I try to include Todaydate as a field in my sql
statements I get the following error.
I'm providing a my source, my code, the error and what I'm trying to
get to.
What am I doing wrong?
Steve
*Inputfile*
2C7CE644 04408185412 ROK6016SPR 953426461789
0001
2C7C3D37 04408142135 ROK6016SPR 485222599128
0001
2D3AAFFD 04503846141 SCP4920KIT 360570162845
0001
2D5E8DFC 04506196732 PM8200KITU 031532538954
0001
2D6496BB 04506592187 PM8200KITS 852948040328
0001
3612C785 05401230725 ROTR650HK 126050310945
0001
*MyCode*
#!/usr/bin/ksh
thefile="testcut.txt"
awk '{print "insert into db(date,f1,f2,f3,f4,f5) values ("$dt
"\""$1"\"\,",
"\""$2"\"\,",
"\""$3"\"\,",
"\""$4"\"\,",
"\""$5"\");"}' dt=`date +'%Y%m%d'` $thefile >> loadfile.sql
*Error*
awk: 0602-538 The field 20050407 must be in the range 0 to 1024.
The input line number is 1. The file is testcut.txt.
The source line number is 1.
*Desired Output*
insert into db(date,f1,f2,f3,f4,f5) values ("2005-Apr-07","2C7CE644",
"04408185412", "ROK6016SPR", "953426461789", "0001");
insert into db(date,f1,f2,f3,f4,f5) values ("2005-Apr-07","2C7C3D37",
"04408142135", "ROK6016SPR", "485222599128", "0001");
insert into db(date,f1,f2,f3,f4,f5) values ("2005-Apr-07","2D3AAFFD",
"04503846141", "SCP4920KIT", "360570162845", "0001");
insert into db(date,f1,f2,f3,f4,f5) values ("2005-Apr-07","2D5E8DFC",
"04506196732", "PM8200KITU", "031532538954", "0001");
insert into db(date,f1,f2,f3,f4,f5) values ("2005-Apr-07","2D6496BB",
"04506592187", "PM8200KITS", "852948040328", "0001");
insert into db(date,f1,f2,f3,f4,f5) values ("2005-Apr-07","3612C785",
"05401230725", "ROTR650HK", "126050310945", "0001");
| |
| Ed Morton 2005-04-13, 8:55 pm |
|
Steve wrote:
> All, I'm trying to create a sql file from a flatfile. I can create the
> file just finebut when I try to include Todaydate as a field in my sql
> statements I get the following error.
> I'm providing a my source, my code, the error and what I'm trying to
> get to.
>
> What am I doing wrong?
Putting a $ in front of an awk variable.
<snip>
> awk '{print "insert into db(date,f1,f2,f3,f4,f5) values ("$dt
awk '{print "insert into db(date,f1,f2,f3,f4,f5) values (" dt
Regards,
Ed.
| |
| Patrick TJ McPhee 2005-04-14, 3:55 am |
| In article <ei2g5155c4guh15v04ckn1o13mpqr2lmns@4ax.com>,
Brian Inglis <Brian.Inglis@SystematicSW.ab.ca> wrote:
% On 8 Apr 2005 03:00:49 GMT in comp.lang.awk, ptjm@interlog.com
% (Patrick TJ McPhee) wrote:
%
% >Printing ' can be problematic in an awk script which is passed as an
% >argument.
%
% Not too hard: just replace each embedded "'" with "'\''".
You could do this, but it won't solve the problem with the majority of
Unix shells. It can be problematic.
--
Patrick TJ McPhee
North York Canada
ptjm@interlog.com
|
|
|
|
|