Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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");


Report this thread to moderator Post Follow-up to this message
Old Post
Steve
04-14-05 01:55 AM


Re: Why won't this AWK work to create SQL with Today's date?

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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
04-14-05 01:55 AM


Re: Why won't this AWK work to create SQL with Today's date?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Patrick TJ McPhee
04-14-05 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:09 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.