count of sundays in month


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers count of sundays in month
# 1  
Old 06-01-2011
Data count of sundays in month

Hi,
How to get count of number of sundays in month in unix shell script ..


ideally i need 2 get last sunday of month
so i used cmd:

for eg: for june:

Code:
cal 06 2011 | tail -2 | head -1 | cut -d" " -f1

hoowever above is wrking for month whose sundays are max=4 but not fr months whose sundyas=5

so i need 2 write funcn if possible to get count of sundays in month..plz hellp..its urgent

Last edited by pludi; 06-01-2011 at 05:54 AM..
# 2  
Old 06-01-2011
Can you try this:

Code:
 cal 11 11|awk 'NR>2{if(NF==7){sun++}; if(NF>0){last=NF}} END{if(last>=1 && last!=7){sun++};print sun}'

This is to count number of sundays

Last edited by kumaran_5555; 06-01-2011 at 07:29 AM..
# 3  
Old 06-01-2011
Quote:
Originally Posted by musu
ideally i need 2 get last sunday of month
Code:
cal 6 2011 | awk 'NF{s=$1}END{print s}'

# 4  
Old 09-01-2011
Code:
cal 08 11|cut -c1-2|awk '{print $1}'|grep [^" "]|grep -v [a-Z]|wc -l

just an alternative to kumaran_5555, a little easier to unstand the code.
# 5  
Old 09-02-2011
Code:
 $ cal 6 2011 | nawk 'NF{print $1|"tail -1"}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

2. Shell Programming and Scripting

Convert From Month Number to Month Name

Hi, I have a script that accepts an input date from the user in yyyy-mm-dd format. I need to get the mm-dd part and convert it to month name. example: 2011-11-15 I want that to become "Nov 15" I don't have the GNU date, I am using an AIX os. Thanks. (1 Reply)
Discussion started by: erin00
1 Replies

3. Shell Programming and Scripting

Add previous Sundays date to filename

I am looking for some scripting help. I need to add a time stamp to a file name. I will append data to a file, and want to add to the file name a time stamp of the previous Sundays date. Any takers? (1 Reply)
Discussion started by: sswagner8839
1 Replies

4. Shell Programming and Scripting

Taking the count of sundays between two date ?

Hi Am using unix Ksh Datecalc and --date functions are not working have two input variables as DATE=01/12/2012 DATE1=23/12/2012 Need output as no of sundays = 4 Can anyone help me pls :( (2 Replies)
Discussion started by: Venkatesh1
2 Replies

5. UNIX for Advanced & Expert Users

How to take the count of all sundays between two dates?

Hi Am Using Unix Ksh I have input DATE1=01/11/2012 DATE2=10/12/2012 need output as count of all sundays between these two dates for examples Sunday count between DATE1 and DATE2 is 5 Can anyone help me... (11 Replies)
Discussion started by: Venkatesh1
11 Replies

6. UNIX for Dummies Questions & Answers

Listing out sundays alone

I am trying to list out only sundays from december 2011. pandeeswaran@ubuntu:~/training$ cal 12 2011|sed -n '3,$p'|sed -e'/^$/d'|awk '{ORS=",";print $1}' 1,4,11,18,25,,pandeeswaran@ubuntu:~/training$ Can anyone help me? Thanks (13 Replies)
Discussion started by: pandeesh
13 Replies

7. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

8. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

9. Shell Programming and Scripting

Cronjob on alternate sundays

I want to set the crontab job for one of my SIEBEL database to refresh it on alternate sundays. Is there anyway I can do it through cron please ? If not whats the alternative ? :confused: Thanks in advance. (6 Replies)
Discussion started by: abhi123
6 Replies

10. Shell Programming and Scripting

List of Sundays for the years 2000 to 2005

hi, i need to write a script that would list me all sundays in the year 2000 and 2005. output need to be just the date . ;) (1 Reply)
Discussion started by: kquest
1 Replies
Login or Register to Ask a Question