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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
03-21-2013, 03:25 AM
|
#1
|
Member
Registered: Aug 2012
Posts: 92
Rep:
|
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
|
|
|
03-21-2013, 03:43 AM
|
#2
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
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.
|
|
|
03-21-2013, 03:44 AM
|
#3
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,247
|
there is no such command, you need to implement it, for example in perl using localtime
|
|
|
03-21-2013, 04:21 AM
|
#4
|
Member
Registered: Aug 2012
Posts: 92
Original Poster
Rep:
|
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....
|
|
|
03-21-2013, 04:49 AM
|
#5
|
Member
Registered: Oct 2007
Location: albuquerque
Distribution: Debian, Arch, Kubuntu
Posts: 366
Rep:
|
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.
|
|
|
03-21-2013, 05:44 AM
|
#6
|
Member
Registered: Oct 2007
Location: albuquerque
Distribution: Debian, Arch, Kubuntu
Posts: 366
Rep:
|
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.
|
|
|
03-21-2013, 09:56 AM
|
#7
|
Moderator
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,960
|
Moderator response
Quote:
Originally Posted by sunnysthakur
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.
|
|
|
03-21-2013, 03:01 PM
|
#8
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep:
|
Code:
date -d "$(date -d "-1 month" +%Y-%m-01) +1 month -1 day" +%m-%d-%Y
02-28-2013
|
|
|
03-22-2013, 07:08 PM
|
#9
|
Member
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862
Rep:
|
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?
|
|
|
03-22-2013, 07:39 PM
|
#10
|
Member
Registered: Oct 2007
Location: albuquerque
Distribution: Debian, Arch, Kubuntu
Posts: 366
Rep:
|
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.
|
|
|
03-23-2013, 06:36 AM
|
#11
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
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.
|
|
|
03-29-2013, 04:09 AM
|
#12
|
Member
Registered: Aug 2012
Posts: 92
Original Poster
Rep:
|
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}'
|
|
|
All times are GMT -5. The time now is 09:55 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|