LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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: 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, 02: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, 02:44 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,945

Rep: Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325
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: 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, 03: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 04:12 AM.
 
Old 03-21-2013, 04: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, 08:56 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
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
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, 06: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, 06: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, 05: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 05:42 AM.
 
Old 03-29-2013, 03: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



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

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

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

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