some months ego


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting some months ego
# 1  
Old 07-26-2005
some months ego

Hi,
how can I format date function to find n (n=1 to 11) months ego ?
For exemple now we are in july and I want to have a variable presenting april.
How should it be :
month=`date +%b`?????
Many thanks before.
# 2  
Old 07-26-2005
Look into this

Could be helpful.

Vino
# 3  
Old 07-26-2005
Thanks , but a problem :
/u04/>date -v -2m
date: illegal option -- v
date: illegal option -- 2
date: illegal option -- m
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
# 4  
Old 07-26-2005
Looks like you are running Solaris.

And you issuing a command which worked under FreeBSD.

vino
# 5  
Old 07-26-2005
Yes I'm under Solaris and this :
mois=`date +%b`; export mois
functions. i get mois=Jul. How can I get two or three month earlier ?
Many thanks.
# 6  
Old 07-26-2005
7 months ago:

ruby -e "t=Time.now.to_a;t[4]-=7;(t[4]+=12;t[5]-=1) if t[4]<1;puts Time.local(*t).strftime('%b')"
# 7  
Old 07-26-2005
Code:
#!/bin/ksh

thisMonth=$(date +%b)
monthsBack=2

echo "thisMonth->[${thisMonth}]"
echo "${monthsBack}-months back-> [$(nawk -v month="${thisMonth}" -v back="$monthsBack}" '\
  BEGIN{n=split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", year);
        for(i=1; i <= n; i++)
           if ( month == year[i]) {
              print ( i > back) ? year[i-back] : year[n-(back-i)]
           }
  }
')]"


Last edited by vgersh99; 07-26-2005 at 03:38 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Naming number to months

Hi, I have many files of monthly means from model simulation such as 1,2,3,4.....12, corresponding to jan, feb, mar,....., dec. e.g. avg_1.nc, avg_2.nc, ............., avg_12.nc. i want to write a shell script such that it should conveet number into months and year such as..... (4 Replies)
Discussion started by: mahesh shinde
4 Replies

2. Post Here to Contact Site Administrators and Moderators

All threads closed after 3 months

I routinely watch for threads that have been unanswered for some time. Recently a rule has been implemented to close threads older than 3 months, which is rather restrictive, because now the last few pages of the unanswered threads section cannot be replied upon, but more importantly eliminates the... (23 Replies)
Discussion started by: figaro
23 Replies

3. Shell Programming and Scripting

Delete 6 months old files

Hi, Iam trying to delete 6 months old files. Iam using the following script -ctime +190 -type f -exec echo rm {} \; Iam getting an error saying -ctime not found. (6 Replies)
Discussion started by: Sompalle Jalaja
6 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

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

6. UNIX for Advanced & Expert Users

Comparing two months

Hi all, Using shell script and awk statements, I manage to get the month and year of the Patch Bundle installed on the system. Now I have to compare month and year of Patch Bundle installed to the Patch Bundle which is desired on the workstation. I am able to do easily comparison of year but not... (1 Reply)
Discussion started by: pankschawla
1 Replies

7. IP Networking

DNS Help - Been trying to do this for months

Ok someone has to be able to help me here. I have the latest webmin, and i have bind i have a domain name called thedigitaldream.co.uk i have one server, just one as im poor so the one server is gunna be the dns, email, web and ftp server. Its only for a small site anyway so it will... (16 Replies)
Discussion started by: matt2kjones
16 Replies
Login or Register to Ask a Question