LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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, 02:25 AM   #1
sunnysthakur
Member
 
Registered: Aug 2012
Posts: 45

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, 02:43 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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, 02:44 AM   #3
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,928

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

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, 03:49 AM   #5
m.a.l.'s pa
Member
 
Registered: Oct 2007
Location: albuquerque
Posts: 198

Rep: Reputation: 34
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 04:12 AM.
 
Old 03-21-2013, 04:44 AM   #6
m.a.l.'s pa
Member
 
Registered: Oct 2007
Location: albuquerque
Posts: 198

Rep: Reputation: 34
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, 08:56 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,281
Blog Entries: 3

Rep: Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446
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, 02:01 PM   #8
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,472
Blog Entries: 6

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, 06:08 PM   #9
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 90
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, 06:39 PM   #10
m.a.l.'s pa
Member
 
Registered: Oct 2007
Location: albuquerque
Posts: 198

Rep: Reputation: 34
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, 05:36 AM   #11
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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 05:42 AM.
 
Old 03-29-2013, 03:09 AM   #12
sunnysthakur
Member
 
Registered: Aug 2012
Posts: 45

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 08:24 AM
dcron - run script last friday of month cotton213 Linux - Software 7 06-25-2012 04:03 PM
[SOLVED] find only new created files from certain date => display folder and path only dragonetti Linux - Newbie 5 10-27-2011 10:38 AM
How to Find: last login information in terms of year-month-date avklinux Linux - General 7 03-14-2009 06:43 PM
Cron Job to run on 2nd and 4th Friday of each month rust8y Linux - General 1 06-25-2007 09:07 PM


All times are GMT -5. The time now is 01:10 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration