cal


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cal
# 1  
Old 05-24-2005
cal

hey everyone. I'm new to UNIX, and I'm having trouble with the cal command. I know that you can display a calendar if you just type in 'cal 3 2005' for example. But how would you do it if you just wanted the calendars displayed to be from March 2005 to June 2005?
Thanks
# 2  
Old 05-24-2005
Bug Calendar which displays the specified months

I have Created a script known as mycal.sh , this is the contents of this script


y=`date '+ %Y' `
echo $1 > file1
tr "a-z" "A-Z" < file1 > az
n=1
ch=`cut -c$n az`

while test "$ch" != "-"
do
f=$f$ch
n=`expr $n + 1`
ch=`cut -c$n az`
done
n=`expr $n + 1`
s=`cut -c$n- az`
for i in $f $s
do
case $i in
JAN) m=1;;
FEB) m=2;;
MAR) m=3;;
APR) m=4;;
MAY) m=5;;
JUN) m=6;;
JUL) m=7;;
AUG) m=8;;
SEP) m=9;;
OCT) m=10;;
NOV) m=11;;
DEC) m=12;;
esac
if [ "$i" = "$f" ]
then
fm=$m
fi
done
if [ $fm -gt $m ]
then
echo "Invalid Range"
fi
while [ $fm -le $m ]
do
cal $fm $y
fm=`expr $fm + 1`
done

save it and run the script by executing this at the command line

sh mycal.sh MAR-JUN


( Likewise you can give as many number of month combination
example
JAN-MAR
MAR-MAY
JAN-DEC ....... etc..

Enjoy
# 3  
Old 05-24-2005
is there just a simple command to do this, instead of typing all that code n stuff? (sorry im really new to unix) Smilie
# 4  
Old 05-24-2005
About the closest you'll get without writing a script is(and assuming you're using GNU cal) - this will show you the prev/current/next month....
Code:
$ cal -3 5 2005
     April 2005             May 2005              June 2005
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
                1  2   1  2  3  4  5  6  7            1  2  3  4
 3  4  5  6  7  8  9   8  9 10 11 12 13 14   5  6  7  8  9 10 11
10 11 12 13 14 15 16  15 16 17 18 19 20 21  12 13 14 15 16 17 18
17 18 19 20 21 22 23  22 23 24 25 26 27 28  19 20 21 22 23 24 25
24 25 26 27 28 29 30  29 30 31              26 27 28 29 30

Else; do something like
Code:
$ for month in 3 4 5 6; do
>   cal $month 2005
> done
     March 2005
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

     April 2005
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

      May 2005
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

      June 2005
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

Cheers
ZB
# 5  
Old 05-24-2005
replyu

Hi

Zazy bob answer was closest & smallest one which i have to agree with

Regards

Victor Vinod Kumar
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract from cal

I was trying to get 1st Sunday in a month. I tried using cal followed by awk NF=1 apparently it would give entire 1st field in that month. Any suggestions (11 Replies)
Discussion started by: penqueen
11 Replies

2. Shell Programming and Scripting

Cal -m on bash

Hi, I want to make Monday as the first day of the month while using cal command when I execute without bash, its working fine /bin/sh cal -m 03 2013 March 2013 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30... (5 Replies)
Discussion started by: infyanurag
5 Replies

3. Homework & Coursework Questions

Using cal in a script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a shell script that will: "Display" the number of days in the current month. For example: September... (1 Reply)
Discussion started by: eaafuddy
1 Replies

4. UNIX for Dummies Questions & Answers

Cal command in UNIX

modify "cal " command to display calenders of the specified months. $ cal jan....aug (1 Reply)
Discussion started by: ssaini
1 Replies

5. Shell Programming and Scripting

another cal command question.

I got this from this board yesterday cal | xargs -n1 | tail -1 which displays the current months days.. for instance if you type this in a shell today you will get 31. I would like to also display the month and year.. something like March 2011 has 31 days. how would I do that? ... (3 Replies)
Discussion started by: rontopia
3 Replies

6. UNIX for Dummies Questions & Answers

cal command

Hello, I wanted to display calender for the previou, current and next month in a single command... I used the command cal -3 for this. But its throwing me a Bad Argument error. I am using HP UX to execute this command. Is this a syntax error, or let me know if there any other ways to... (6 Replies)
Discussion started by: atlantis
6 Replies

7. UNIX for Dummies Questions & Answers

Cal question

This probably would be a cake walk for you, but i am having trouble with this. I am trying to print every tuesday of the month from cal, and the FS default is space. There is one row that has few spaces at the beginning and so when i print $3, those spaces get ingnored and a different day gets... (2 Replies)
Discussion started by: Vin
2 Replies

8. Shell Programming and Scripting

Formating cal output

Hi Gurus, In my Cal output i want to cut the date of 2nd saturday how tyo achive this. for eg in the below output i need that second saturday 13 to be cut. crypto $ cal January 2007 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26... (2 Replies)
Discussion started by: Krrishv
2 Replies

9. AIX

doubt in cal command

I am new to unix... How to get all the saturdays of a specific year? for a specific month, i tried as below.. cal 02 2006 | awk '{print $7}' but it is not giving all saturdays.... can anyone help me with this? Thanks in advance, Sumi (9 Replies)
Discussion started by: sumi
9 Replies

10. UNIX for Dummies Questions & Answers

Cal command

I am trying to configure the cal command to recognize the month names. When you type: cal - you get the calander for the current month of the current year. Is there a way of making the system recognize March, and Mar. So I could type: cal March or cal mar and get the same response as cal.... (5 Replies)
Discussion started by: Astudent
5 Replies
Login or Register to Ask a Question