Listing out sundays alone


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Listing out sundays alone
# 1  
Old 01-10-2012
Listing out sundays alone

I am trying to list out only sundays from december 2011.
Code:
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
# 2  
Old 01-10-2012
Code:
for i in 2011 2012
do
  for j in 1 2 3 4 5 6 7 8 9 10 11 12
  do
     cal $j $i  | cut -c 1-3 | nawk -v mon=$j -v yr=$i '
                                 /[0-9]/{printf("Sunday, %02d/%02d/%d\n", mon, $1, yr)}'
  done
done

I used nawk because I ran this on solaris, use awk or gawk otherwise.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 01-10-2012
Or perhaps something like this?

Code:
cal -s 12 2011 | awk '/^[ ][0-9]/ || /^[0-9]/ {print $1}'

# 4  
Old 01-10-2012
Quote:
Originally Posted by verdepollo
Or perhaps something like this?

Code:
cal -s 12 2011 | awk '/^[ ][0-9]/ || /^[0-9]/ {print $1}'

-s switch is not supported in my ubuntu.
Code:
pandeeswaran@ubuntu:~/training$ cal -s 12 2011
Usage: cal [general options] [-hjy] [[month] year]
       cal [general options] [-hj] [-m month] [year]
       ncal [general options] [-bhJjpwySM] [-s country_code] [[month] year]
       ncal [general options] [-bhJeoSM] [year]
General options: [-NC3] [-A months] [-B months]
For debug the highlighting: [-H yyyy-mm-dd] [-d yyyy-mm]

pandeeswaran@ubuntu:~/training$ uname -a
Linux ubuntu 3.0.0-14-generic #23-Ubuntu SMP Mon Nov 21 20:28:43 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
pandeeswaran@ubuntu:~/training$

Tried ncal too:
Code:
pandeeswaran@ubuntu:~/training$ ncal -s 12 2011 | awk '/^[ ][0-9]/ || /^[0-9]/ {print $1}'
ncal: 12: invalid country code

---------- Post updated at 10:09 PM ---------- Previous update was at 10:06 PM ----------

Quote:
Originally Posted by jim mcnamara
Code:
for i in 2011 2012
do
  for j in 1 2 3 4 5 6 7 8 9 10 11 12
  do
     cal $j $i  | cut -c 1-3 | nawk -v mon=$j -v yr=$i '
                                 /[0-9]/{printf("Sunday, %02d/%02d/%d\n", mon, $1, yr)}'
  done
done

I used nawk because I ran this on solaris, use awk or gawk otherwise.

Thanks!
But i want the sundays only in december 2011 alone.
My output should be in comma separated format such as:
Code:
4,11,18,25

.

Last edited by pandeesh; 01-10-2012 at 12:37 PM.. Reason: tried ncal
# 5  
Old 01-10-2012
Quote:
Originally Posted by pandeesh
-s switch is not supported in my ubuntu.
Use uppercase "S" in Ubuntu.
# 6  
Old 01-10-2012
Quote:
Originally Posted by verdepollo
Use uppercase "S" in Ubuntu.
Code:
pandeeswaran@ubuntu:~/training$ cal -S 12 2011
Usage: cal [general options] [-hjy] [[month] year]
       cal [general options] [-hj] [-m month] [year]
       ncal [general options] [-bhJjpwySM] [-s country_code] [[month] year]
       ncal [general options] [-bhJeoSM] [year]
General options: [-NC3] [-A months] [-B months]
For debug the highlighting: [-H yyyy-mm-dd] [-d yyyy-mm]

# 7  
Old 01-10-2012
Just lose the switch completely.
Code:
cal 12 2011 | awk '/^[ ][0-9]/ || /^[0-9]/ {print $1}'

4
11
18
25

This User Gave Thanks to methyl For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

3. 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

4. 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

5. UNIX Desktop Questions & Answers

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

6. UNIX for Dummies Questions & Answers

listing files

how would i list all files that began witha "t" and have any number of characters after the "t"? (2 Replies)
Discussion started by: trob
2 Replies

7. UNIX for Dummies Questions & Answers

Listing files

how would i list all files, directories and exectable files in my directory? is there anyway to find out what date a file was created? Thanks!! (2 Replies)
Discussion started by: trob
2 Replies

8. 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

9. 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

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question