calculate 13 months ago


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting calculate 13 months ago
# 1  
Old 11-16-2007
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 ( https://www.unix.com/answers-frequent...rithmetic.html) but it didn't help me ...

My Unix is Solaris.

does somebody can help ?
thanks , Andrea.
# 2  
Old 11-16-2007
Code:
$ cat 13months_ago
#! /usr/bin/ksh

for input in 20071115 20071105 20070105 ; do

        year=${input%????}
        day=${input#??????}
        month=${input#????}
        month=${month%??}
        month=${month#0}
        day=${day#0}
        print -n $input $year $month $day

        ((year=year-1))
        ((month=month-1))
        if ((!month)) ; then
                ((year=year-1))
                month=12
        fi
        typeset -Z2 newday newmonth
        newday=$day
        newmonth=$month
        output=${year}${newmonth}${newday}
        print -- " -->" $year $month $day $output
done
exit 0
$ ./13months_ago
20071115 2007 11 15 --> 2006 10 15 20061015
20071105 2007 11 5 --> 2006 10 5 20061005
20070105 2007 1 5 --> 2005 12 5 20051205
$

# 3  
Old 11-16-2007
re.: calculate 13 months ago

Perderabo, thanks but your example didnīt works for me.

but I found the solution:

in my main program I calculate 13 months ago

hoje=`date +%Y%m%d`
data_13m=`expr ${hoje} - 10200`

and then, I've send the variable data_13m to the file.scl

export PAR_SCL3=${data_13m}

in the file.scl I did:

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

and it worked !
by.
# 4  
Old 11-16-2007
You are in effect subtracting 1 year and 2 months from the date. If that is your defintion of "13 months ago", you could change my script to
((month=month-2))
if ((month<1)) ; then

Note that your method will fail if the original date is in january or february.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find a file that's modified more than 2 days ago but less than 5 days ago?

How to find a file that's modified more than 2 days ago but was modified less than 5 days ago by use of any Linux utility ? (4 Replies)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

How to calculate months and display in shell scripting

I just want to know, how do we calculate the months in shell scripting. If i give the input as 20-01-2011, the output should be 20-02-2011, 20-03-2011 or 20-04-2011........ How do i get this ? Cheers. (6 Replies)
Discussion started by: sachin24
6 Replies

3. Shell Programming and Scripting

how to calculate the time 10 mins ago?? unix

Hi guys, Im trying to subtract time in ksh script. i.e. basically im querying a database and i want to get the time 10mins before hand..(from) in ksh CurrMin=$(date "+%M") from=`expr $CurrMin - 10` to=$CurrMin however if i run this i say at 2 or 3 mins past the hour, i.e.... (7 Replies)
Discussion started by: k00061804
7 Replies

4. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: andrea_mussap
4 Replies

5. Shell Programming and Scripting

Cron to run first day of month to calculate date 3 months ago

Hi, I would like to find out how can i calculate a date which is 3 months ago. I intend to run a cron job on the 1st of every month, and calculate the month 4 months earlier from the date. For example, if today's date is 1st May 2007, i would like to return 012007( January 2007). i can get... (1 Reply)
Discussion started by: new2ss
1 Replies

6. UNIX for Dummies Questions & Answers

deleting files with dates 3 months ago

please help me with this????? :confused: :confused: i need to create a program that will run in unix that will delete all files in a given directory that is at least 3 months old. first the program will need to automatically know what date it is right now to determine the files it will... (3 Replies)
Discussion started by: godalle
3 Replies
Login or Register to Ask a Question