LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-21-2013, 03:25 AM   #1
sunnysthakur
Member
 
Registered: Aug 2012
Posts: 92

Rep: Reputation: Disabled
How to find/display out last Friday's date of the month


Hello,

Can you please help me find/display out last Friday's date of the month using command in Unix/Linux
 
Old 03-21-2013, 03:43 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
This seems like a homework question, so I'll hint at the answer. Look at the man page of date. Read the descriptions of the -d argument and the +format.
 
Old 03-21-2013, 03:44 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,247

Rep: Reputation: 7689Reputation: 7689Reputation: 7689Reputation: 7689Reputation: 7689Reputation: 7689Reputation: 7689Reputation: 7689Reputation: 7689Reputation: 7689Reputation: 7689
there is no such command, you need to implement it, for example in perl using localtime
 
Old 03-21-2013, 04:21 AM   #4
sunnysthakur
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
I tried with date --date with below strings
'2 friday' #This show 2 friday from now
'last friday' #This shows previous firday of month

but this is not showing what i want....
 
Old 03-21-2013, 04:49 AM   #5
m.a.l.'s pa
Member
 
Registered: Oct 2007
Location: albuquerque
Distribution: Debian, Arch, Kubuntu
Posts: 366

Rep: Reputation: 139Reputation: 139
Last Friday's date of the month:

$ date --date='last friday' +%d
15

Last edited by m.a.l.'s pa; 03-21-2013 at 05:12 AM.
 
Old 03-21-2013, 05:44 AM   #6
m.a.l.'s pa
Member
 
Registered: Oct 2007
Location: albuquerque
Distribution: Debian, Arch, Kubuntu
Posts: 366

Rep: Reputation: 139Reputation: 139
Very cool; for those who are interested, see the OP's thread here: http://ubuntuforums.org/showthread.p...1#post12567241

So, I think this is what was wanted:

Code:
$ date +"$(cal -N |awk '/^Fr/ {print $(NF)}') %B"
29 March
We'll see what the OP says.
 
Old 03-21-2013, 09:56 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,960
Blog Entries: 46

Rep: Reputation: 3188Reputation: 3188Reputation: 3188Reputation: 3188Reputation: 3188Reputation: 3188Reputation: 3188Reputation: 3188Reputation: 3188Reputation: 3188Reputation: 3188
Moderator response

Quote:
Originally Posted by sunnysthakur View Post
Hello,

Can you please help me find/display out last Friday's date of the month using command in Unix/Linux
Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.
 
Old 03-21-2013, 03:01 PM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
date -d "$(date -d "-1 month" +%Y-%m-01) +1 month -1 day" +%m-%d-%Y
02-28-2013
 
Old 03-22-2013, 07:08 PM   #9
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 91
Well it has been well over a day since the original post so I have a question for all contributors to this thread. I'm not totally clear what the OP is after but what about the "cal" command? The entire present month is displayed like a calendar and it's easy to see what the date was last Friday. ?? Comments? Am I way off base here?
 
Old 03-22-2013, 07:39 PM   #10
m.a.l.'s pa
Member
 
Registered: Oct 2007
Location: albuquerque
Distribution: Debian, Arch, Kubuntu
Posts: 366

Rep: Reputation: 139Reputation: 139
Judging by what the OP wrote in the Ubuntu thread that was also started, I assume that what was wanted was a command that would output the date of the final Friday of the current month. In that thread, the OP wrote, "The output date should be 29 march...." I'm guessing that that he didn't want something like echo "29 march", and that simply looking at a calendar wouldn't do, either.
 
Old 03-23-2013, 06:36 AM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I had read the problem as the day of the month for "last Friday", instead of the date of the final Friday of the month. Incidentally, "last Friday" is a valid argument for the -d argument.

Being able to clearly express a problem requires a student to first organize his thoughts. This could even lead to a solution. Maybe, for these homework problems, we should ask the original posters to restate the problem clearly and unambiguously if the description is muddled, and then to provide information on what they tried, or a description on how they believe they need to proceed to solve the problem.

Last edited by jschiwal; 03-23-2013 at 06:42 AM.
 
Old 03-29-2013, 04:09 AM   #12
sunnysthakur
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
This also works for me

cal 03 2013 | awk 'NR==1 {m=substr($1, 1, 3); y=$2} NF>5 {d=$6} END {print "Friday", m, d, y}'
 
  


Reply

Tags
command, date, linux, unix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cronjob to run a command at first friday of each month a9b8c2 Linux - General 5 10-19-2012 09:24 AM
dcron - run script last friday of month cotton213 Linux - Software 7 06-25-2012 05:03 PM
[SOLVED] find only new created files from certain date => display folder and path only dragonetti Linux - Newbie 5 10-27-2011 11:38 AM
How to Find: last login information in terms of year-month-date avklinux Linux - General 7 03-14-2009 07:43 PM
Cron Job to run on 2nd and 4th Friday of each month rust8y Linux - General 1 06-25-2007 10:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration