The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
calculate 13 months ago andrea_mussap Shell Programming and Scripting 3 11-16-2007 03:18 PM
Cron to run first day of month to calculate date 3 months ago new2ss Shell Programming and Scripting 1 05-17-2007 02:28 AM
some months ego big123456 Shell Programming and Scripting 8 07-27-2005 03:31 AM
Comparing two months pankschawla UNIX for Advanced & Expert Users 1 02-11-2004 07:32 AM
DNS Help - Been trying to do this for months matt2kjones IP Networking 16 09-28-2002 09:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-16-2007
andrea_mussap andrea_mussap is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
calculate 13 months ago

hi,
I have a big file that contains datas since 4 years ago.

I need re-create this file but just lines that are 13 months ago from today.

see what I have: ( I have a file.ksh that calls this file.scl ok !!)

======== file.scl ================
/STATISTICS=stderr
/STABLE
/NODUPLICATES
/EXECUTE " today=`date +%Y%m%d` "
/EXECUTE " 13m_ago=`expr ${today} - 10000` "
/INFILE=$PAR_SCL1
/FIELD=(CONTA_CORRENTE, POSITION=1, SIZE=13)
/FIELD=(DATA_VENCIMENTO, POSITION=50, SIZE=10)
/CONDITION=(cond1, TEST=(DATA_VENCIMENTO > ($13m_ago) )
/INCLUDE=(CONDITION=cond1)
/KEY=(NUMERO_FATURA, ASCENDING)
/OUTFILE=$PAR_SCL2
/FIELD=(CONTA_CORRENTE, POSITION=1, SIZE=13)
/FIELD=(DATA_VENCIMENTO, POSITION=50, SIZE=10)

============================================

"DATA_VENCIMENTO" is the date that have to be in the maximum equal 13 months ago.
the layout of DATA_VENCIMENTO is 20071115 , for exemple.


I've already see the topic ( Yesterdays Date/Date Arithmetic) but it didn't help me ...

My Unix is Solaris.

does somebody can help ?
thanks , Andrea. [ 16/11/2007 ]
  #2 (permalink)  
Old 11-18-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 921
Post

It's a bit ugly but:

sh/bash/ksh etc
Code:
month=`date +%m`
day=`date +%M`
year=`date +%Y`

count=13

while [ $count -gt 0 ]
do
    count=`expr $count - 1`
    month=`expr $month - 1`
    if [ $month -lt 1 ]
    then
        month=12
        year=`expr $year -1`
    fi
done

compare_date="${year}${month}${day}"

while <***read the file***>
do
    if [ $DATA_VENCIMENTO -lt $compare_date ]
    then
        <***do stuff***>
    fi
done
  #3 (permalink)  
Old 11-18-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,402
Umm... that could return an invalid date when run at the end of a "long" month. For example, run date is 20071231, code returns 20061131
  #4 (permalink)  
Old 11-21-2007
andrea_mussap andrea_mussap is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
re.: calculate 13 months ago

hi, thanks 4 the answers, but I could resolve in a better simple way :

in my main program I did :
.
.
.
hoje=`date +%Y%m%d`
data_13m=`expr ${hoje} - 10200`

export PAR_SCL3=${data_13m}

EXECUTA "sortcl /sp=${DIR_PROG_SCL}/saida_13meses.scl" \


and in the saida_13meses.scl I did :

/EXECUTE "$PAR_SCL3"
/INFILE=$PAR_SCL1
/FIELD=(CONTA_CORRENTE, POSITION=1, SIZE=13)
/FIELD=(NUMERO_FATURA, POSITION=14, SIZE=14)
/FIELD=(DATA_VENCIMENTO, POSITION=50, SIZE=10)
/CONDITION=(cond1, TEST=(DATA_VENCIMENTO > $PAR_SCL3 ))
/INCLUDE=(CONDITION=cond1)

bye
  #5 (permalink)  
Old 11-21-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 921
Quote:
Originally Posted by Ygor View Post
Umm... that could return an invalid date when run at the end of a "long" month. For example, run date is 20071231, code returns 20061131
That shouldn't matter though, we don't want to know a nice calander date 13 months ago, we want to find stuff older than that to flag.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0