Sponsored Content
Full Discussion: Extract from cal
Top Forums Shell Programming and Scripting Extract from cal Post 302912874 by rbatte1 on Tuesday 12th of August 2014 11:18:26 AM
Old 08-12-2014
Are we looking at this the wrong way? The output from cal will have a header row, then the next line will always have Saturday in it. You can see what the Saturday is by trimming off things you don't need, then work out Sunday from that.

Consider:-
Code:
topline=`cal $mm $yyyy | head -3 | tail -1`
Sat1="${topline##* }"
((Sun1=$Sat1+1))
if [ $Sun1 -eq 8 ]
then
   Sun1=1
fi

So, first Saturday of a month is the value of Sat1 and the first Sunday of a month is the value of Sun1

Okay, it's a few lines of code, but it works.


I hope that this helps,
Robin

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As does:-
Code:
cal $1 $2|awk 'NF == 7 && NR > 2 {print $1; exit}'

....posted by Don earlier that I hadn't fully read. Smilie

Last edited by rbatte1; 08-12-2014 at 12:21 PM.. Reason: Commented on Don's earlier suggestion
 

10 More Discussions You Might Find Interesting

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

2. UNIX for Dummies Questions & Answers

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

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

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

5. Shell Programming and Scripting

parsing cal cmd

:o given a date example mm dd yyyy 01 02 1999 how can your parse cal 01 1999 and find the date in the above case 02 and display what the actual day was eg s m t w t f s Thanks in advance Dragrid (7 Replies)
Discussion started by: dragrid
7 Replies

6. Shell Programming and Scripting

Get day of week from cal

Hi all, I am trying to get dow from cal using below script #! /bin/bash YEAR=`echo $1 | cut -c 1-4` MONTH=`echo $1 | cut -c 5-6` DAY=`echo $1 | cut -c 7-8` for i in 1 2 3 4 5 6 7 do dayofweek=`cal $MONTH $YEAR | awk '$i == $DAY {printf("%s","$i")}'` echo $dayofweek... (4 Replies)
Discussion started by: bzylg
4 Replies

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

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

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

10. 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
CAL(1)							    BSD General Commands Manual 						    CAL(1)

NAME
cal, ncal -- displays a calendar and the date of Easter SYNOPSIS
cal [-3hjy] [-A number] [-B number] [[month] year] cal [-3hj] [-A number] [-B number] -m month [year] ncal [-3hjJpwy] [-A number] [-B number] [-s country_code] [[month] year] ncal [-3hJeo] [-A number] [-B number] [year] ncal [-CN] [-H yyyy-mm-dd] [-d yyyy-mm] DESCRIPTION
The cal utility displays a simple calendar in traditional format and ncal offers an alternative layout, more options and the date of Easter. The new format is a little cramped but it makes a year fit on a 25x80 terminal. If arguments are not specified, the current month is dis- played. The options are as follows: -h Turns off highlighting of today. -J Display Julian Calendar, if combined with the -e option, display date of Easter according to the Julian Calendar. -e Display date of Easter (for western churches). -j Display Julian days (days one-based, numbered from January 1). -m month Display the specified month. If month is specified as a decimal number, it may be followed by the letter 'f' or 'p' to indicate the following or preceding month of that number, respectively. -o Display date of Orthodox Easter (Greek and Russian Orthodox Churches). -p Print the country codes and switching days from Julian to Gregorian Calendar as they are assumed by ncal. The country code as deter- mined from the local environment is marked with an asterisk. -s country_code Assume the switch from Julian to Gregorian Calendar at the date associated with the country_code. If not specified, ncal tries to guess the switch date from the local environment or falls back to September 2, 1752. This was when Great Britain and her colonies switched to the Gregorian Calendar. -w Print the number of the week below each week column. -y Display a calendar for the specified year. -3 Display the previous, current and next month surrounding today. -A number Display the number of months after the current month. -B number Display the number of months before the current month. -C Switch to cal mode. -N Switch to ncal mode. -d yyyy-mm Use yyyy-mm as the current date (for debugging of date selection). -H yyyy-mm-dd Use yyyy-mm-dd as the current date (for debugging of highlighting). A single parameter specifies the year (1-9999) to be displayed; note the year must be fully specified: ``cal 89'' will not display a calendar for 1989. Two parameters denote the month and year; the month is either a number between 1 and 12, or a full or abbreviated name as speci- fied by the current locale. Month and year default to those of the current system clock and time zone (so ``cal -m 8'' will display a calen- dar for the month of August in the current year). Not all options can be used together. For example ``-3 -A 2 -B 3 -y -m 7'' would mean: show me the three months around the seventh month, three before that, two after that and the whole year. ncal will warn about these combinations. A year starts on January 1. Highlighting of dates is disabled if stdout is not a tty. SEE ALSO
calendar(3), strftime(3) HISTORY
A cal command appeared in Version 5 AT&T UNIX. The ncal command appeared in FreeBSD 2.2.6. AUTHORS
The ncal command and manual were written by Wolfgang Helbig <helbig@FreeBSD.org>. BUGS
The assignment of Julian-Gregorian switching dates to country codes is historically naive for many countries. Not all options are compatible and using them in different orders will give varying results. BSD
March 14, 2009 BSD
All times are GMT -4. The time now is 02:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy