All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Adam T. Bowen" <adam.bowen@connectinternetsolutions.com>
To: Martin Klier <martin.klier@atu.de>
Cc: linux-admin@vger.kernel.org
Subject: Re: Special date/cal needs eg. "thrid friday of july"
Date: Fri, 12 Jan 2007 15:02:44 +0000	[thread overview]
Message-ID: <45A7A314.9090904@connectinternetsolutions.com> (raw)
In-Reply-To: <200701111624.02217.martin.klier@atu.de>

Hi,

Martin Klier wrote:
> Hi Linux Admins,
> 
> is there a command to get something like "thrid friday of july" or "second 
> wednesday each month"? I crossread the manuals for date and gcal, but it 
> seems to be impossible. Next thing I found was gcal, with 
> "--period-of-fixed-dates", but I have not been able to get useful results, 
> and 
> date -d "35 tuesday" (35th tuesday of a year), but I have not been able to 
> limit it to months nor selecting the year (by the way, I do not need it).
> 
> Has somebody experience with this one, and can you give me a hint where to 
> look, or even an example?
> 
> Thanks a lot in advance,

I love the --date GNU extension, but I tried a number of different
syntaxes to get it to do what you wanted without any luck.  So I thought
a one line pipe would be fun:

cal 7 2007 | awk -F. 'NR > 2{print substr($1,5*3+1,2)}' | grep '[0-9]' |
awk 'NR == 3 {print $1}'

You set the day you're interested in through the first integer of the
second parameter of the substr call of the awk command.  0=Sunday
(0*3+1), 1=Monday (1*3+1) etc.  You set the week number with the 'NR ==
n' part of the final awk.  You set the month and year with the
parameters to cal.  It invokes awk twice which if used in a very tight
loop could be a problem.  It would be easy to merge the awk | grep | awk
into one awk command, but it starts to look more like program code on a
single line rather than a series of simple(-ish) commands.

Cheers

Adam

      parent reply	other threads:[~2007-01-12 15:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-11 15:23 Special date/cal needs eg. "thrid friday of july" Martin Klier
2007-01-11 16:56 ` Kirkwood, David A.
2007-01-11 17:47 ` Benoît Rouits
2007-01-11 20:26 ` Doug Knight
2007-01-12 15:02 ` Adam T. Bowen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45A7A314.9090904@connectinternetsolutions.com \
    --to=adam.bowen@connectinternetsolutions.com \
    --cc=linux-admin@vger.kernel.org \
    --cc=martin.klier@atu.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.