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

filter on dates
Hi,
I have a datafile which contains two date columns.
I'm using the following logic to create two new files base on these dates.
It seems straight forward enough but I can't seem to get it to work.

awk 'BEGIN{
spcs="        "
}
{
f = substr($0, 97, 8)  #dte_str
o = substr($0, 198, 8) #dte_ver

if ( (f != spcs && f >= 19950401)
|| (o != spcs && o >= 19950401) ) #YYYYMMDD
{
print f o > "current.txt"
}
if  if ( (f == spcs || f < 19950401)
&& (o == spcs || o < 19950401) ) #YYYYMMDD
{
print f o > "history.txt"
}
} END { }' DATA.txt

What is incorrect with this?
Thanks in advance.
Andre

Report this thread to moderator Post Follow-up to this message
Old Post
AJ Norman
03-27-04 04:09 AM


Re: filter on dates
Is there a typo here? You have "if if" after writing to current.txt.

It's difficult to propose a solution when we don't know what the
output is supposed to be. Is every line to be written to either
current.txt or history.txt? It looks to me like some lines are to be
written to neither. Is that what you want?

DKM



On 24 Mar 2004 13:03:43 -0800, norman_andre@hotmail.com (AJ Norman)
wrote:

>Hi,
>I have a datafile which contains two date columns.
>I'm using the following logic to create two new files base on these dates.
>It seems straight forward enough but I can't seem to get it to work.
>
>awk 'BEGIN{
>spcs="        "
>}
>{
>f = substr($0, 97, 8)  #dte_str
>o = substr($0, 198, 8) #dte_ver
>
> if ( (f != spcs && f >= 19950401)
>     || (o != spcs && o >= 19950401) ) #YYYYMMDD
>  {
>             print f o > "current.txt"
>  }
> if  if ( (f == spcs || f < 19950401)
>     && (o == spcs || o < 19950401) ) #YYYYMMDD
>  {
>             print f o > "history.txt"
>  }
>} END { }' DATA.txt
>
>What is incorrect with this?
>Thanks in advance.
>Andre


To contact me directly, send EMAIL to (single letters all)
DEE_KAY_EMM AT EarthLink.net. [For example X_X_X@EarthLink.net.]

Report this thread to moderator Post Follow-up to this message
Old Post
Doug McClure
03-27-04 04:09 AM


Re: filter on dates

AJ Norman wrote:
> Hi,
> I have a datafile which contains two date columns.
> I'm using the following logic to create two new files base on these dates.
> It seems straight forward enough but I can't seem to get it to work.
>
> awk 'BEGIN{
> spcs="        "
> }
> {
> f = substr($0, 97, 8)  #dte_str
> o = substr($0, 198, 8) #dte_ver
>
>  if ( (f != spcs && f >= 19950401)

I might be wrong, but when you compare a string "f" and a numeric
"19950401", I think that's treated as a string comparison rather than a
numeric one. To get a numeric comparison, try forcing f to a numeric value:

if ( (f != spcs && (1.0*f) >= 19950401)

<snip>
> } END { }' DATA.txt

Get rid of the "END { }" as it does nothing.

Ed.


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-27-04 04:09 AM


Re: filter on dates
Ed Morton <morton@lsupcaemnt.com> wrote in message news:<c3sva9$33q@netnews.proxy.lucent.co
m>...
> AJ Norman wrote: 
>
> I might be wrong, but when you compare a string "f" and a numeric
> "19950401", I think that's treated as a string comparison rather than a
> numeric one. To get a numeric comparison, try forcing f to a numeric value
:
>
> if ( (f != spcs && (1.0*f) >= 19950401)
>
> <snip> 
>
> Get rid of the "END { }" as it does nothing.
>
> 	Ed.


That will do it.
Thanks Ed.

Report this thread to moderator Post Follow-up to this message
Old Post
AJ Norman
03-27-04 04:09 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 03:26 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.