General
cancel
Showing results for 
Search instead for 
Did you mean: 

Last Sunday of the month with awk

SOLVED
Go to solution
wojtek75
Frequent Advisor

Last Sunday of the month with awk

Hi,

this is how to get last day of the month:
cal|awk 'END{print DAY};{if (NF<1) {next};DAY=$NF}'

Is there a similar way to get the last Sunday and last Friday of the month? Thanks in advance.
4 REPLIES
Steven E. Protter
Exalted Contributor

Re: Last Sunday of the month with awk

Shalom,

The right tool for the right job.

http://mirrors.develooper.com/hpux/caljd-2.25.sh

http://mirrors.develooper.com/hpux/caljd-2.2.pl

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
wojtek75
Frequent Advisor

Re: Last Sunday of the month with awk

Thanks, but I need it for production machine in a corporation. A lot of compliance problems with a new scripts there and your advice is not feasible for me, but thanks.

What about awk version? No chance to do it that way?
Duncan Edmonstone
Honored Contributor
Solution

Re: Last Sunday of the month with awk

But this *is* shell script:

cal|awk 'END{print DAY};{if (NF<1) {next};DAY=$NF}'

Piping output of cal into awk...

anyway if you want a quick and dirty method of doing this I guess something like:

cal | awk '{ print $6 }' | sed /^$/d | tail -1

would work for Friday, and obviously:

cal | awk '{ print $1 }' | sed /^$/d | tail -1

for Sunday

HTH

Duncan

HTH

Duncan
wojtek75
Frequent Advisor

Re: Last Sunday of the month with awk

Thanks, this is what I was expecting for.