## Extract from cal

Extract from cal
# 8
Quote:
Originally Posted by protocomm
Excuse me, i don't understand completely the post.
Look at the output from cal 6 2014:
The code you suggested:
will print 8, but the 1st Sunday in June, 2014 is the 1st; not the 8th.

The code I suggested will print 1 in this case and should print the correct day number for the 1st Sunday no matter what day of the week the 1st day of the month is.
 Don Cragun View Public Profile for Don Cragun Find all posts by Don Cragun
# 9
Quote:
Originally Posted by Don Cragun
Look at the output from cal 6 2014:
The code you suggested:
will print 8, but the 1st Sunday in June, 2014 is the 1st; not the 8th.

The code I suggested will print 1 in this case and should print the correct day number for the 1st Sunday no matter what day of the week the 1st day of the month is.
Yes it's true, my answer to the post was so quickly, thx.
 protocomm View Public Profile for protocomm Find all posts by protocomm
# 10
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:- 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

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

Last edited by rbatte1; 08-12-2014 at 12:21 PM.. Reason: Commented on Don's earlier suggestion
 rbatte1 View Public Profile for rbatte1 Visit rbatte1's homepage! Find all posts by rbatte1
# 11
I think you're onto something! The fourth line of the calendar is always complete, why not calculate from it?

That's robust/complete enough to work on any day of the week. 1 for Sunday, 7 for Saturday.

There's probably a smarter way with modulous, but that's tricky and longwinded when numbers count from 1 instead of 0, so maybe not...
 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688
# 12
Nobody remembers my datecalc script.

Well, datecalc provides the primatives needed to handle any date calculation. To find the first Sunday...

Here is a sample run...
My datecalc script is posted here: datecalc
 Perderabo View Public Profile for Perderabo Find all posts by Perderabo

Test Your Knowledge in Computers #384
Difficulty: Medium
The Unix df command reports damaged disk space on file systems.
True or False?

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

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

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

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

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

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

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

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

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

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