Get the date for the last Saturday of a given month

cal 04 2012 | awk '{ \$7 && X=\$7 } END { print X }'
If your locale has Monday as the first day of the week, like mine in the UK, change the two \$7 into \$6
Sample Output
`28`

2
2012-05-06 23:43:21

2 Alternatives + Submit Alt

• Choosing your year and month. You only need the gnu date command and bash. desiredDay of the week is (1..7); 1 is Monday. If you want desiredDay of week (0..6); 0 is Sunday `desiredDay=6; year=2012; month=5; n=0; while [ \$(date -d "\$year-\$((month+1))-1 - \$n day" "+%w") -ne \$desiredDay ]; do n=\$((n+1)); done; date -d "\$year-\$((month+1))-1 - \$n day" "+%x"` Show Sample Output

0
desiredDay=6; year=2012; month=5; n=0; while [ \$(date -d "\$year-\$((month+1))-1 - \$n day" "+%u") -ne \$desiredDay ]; do n=\$((n+1)); done; date -d "\$year-\$((month+1))-1 - \$n day" "+%x"
· 2012-05-17 12:02:30
• This is a little trickier than finding the last Sunday, because you know the last Sunday is in the first position of the last line. The trick is to use the NF less than or equal to 7 so it picks up all the lines then grep out any empty lines. Show Sample Output

-2
cal 04 2012 | awk 'NF <= 7 { print \$7 }' | grep -v "^\$" | tail -1
· 2012-05-03 16:57:45

What Others Think

I only get '31' from cal 04 2012 | awk '{ \$7 && X=\$7 } END { print X }' last day of current month...
Habitual · 637 weeks ago
Do you know about the basketball stars? It's one of my favorite games. This type of game is fascinating. In two-player mode, we may play with our friends, while in single-player mode, we can play alone. You can try it in your free time, and you will like it.
willardg162 · 112 weeks and 5 days ago
Thank you again for all the knowledge tunnel rush you distribute, Good post. I was very thinking about the post, it's quite motivating I must confess. I such as visiting you site considering that I constantly discover interesting articles like this one.
abel1303 · 87 weeks and 2 days ago
What a sensational blog! This blog is too much amazing in all aspects. Especially, it looks awesome and the content available on it is utmost qualitative. team sports
mohsinkhatri · 75 weeks and 4 days ago
No doubt this is an excellent post I got a lot of knowledge after reading good luck. Theme of blog is excellent there is almost everything to read, Brilliant post. lifeguard certificate near me
mohsinkhatri · 75 weeks and 3 days ago
Thank you for this fascinating post, I am happy I observed this website on Google. Not just content, in fact, the whole site is fantastic. https://ru.herbiware.com
mohsinkhatri · 75 weeks and 1 day ago
Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also https://mtpolice-1st.com/
mohsinkhatri · 75 weeks ago
mohsinkhatri · 74 weeks and 4 days ago
Nice blog, I will keep visiting this blog very often. sim cards
mohsinkhatri · 73 weeks and 6 days ago
I really thank you for the valuable info on this great subject and look forward to more great posts. Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! All the best! Sad Tik Tok Songs
mohsinkhatri · 73 weeks and 1 day ago
I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well. https://youtu.be/iVgloD2hHc8
mohsinkhatri · 72 weeks and 6 days ago
Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome! Said Shiripour Affiliate Marketing
mohsinkhatri · 72 weeks and 1 day ago
I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. situs slot terpercaya
mohsinkhatri · 71 weeks ago
Over the last two decades, we have developed bespoke solutions like Broaching - Internal Broaching Machine, External Broaching Machines, CNC Helical broaching and Surface Broaching, Table-Up Surface Broaching Machines, Table-Up Broaching Machines, Post Hobbing solutions - Gear Tooth Deburring, PLC Gear Tooth Chamfering, CNC Gear tooth Chamfering, CNC Gear Tooth Rounding Machine, CNC Gear Tooth Pointing Machines, CNC Swaging Machines, CNC/ PLC metal cutting Special Purpose Machines that includes automation, drilling, turning, milling, boring and robotic material handling systems. Gear Tooth Chamfering
mohsinkhatri · 68 weeks ago
Thanks a lot; I've been hunting for this material for a while, and it's been incredibly useful at the office. cut mover
irene167 · 67 weeks and 6 days ago
Compare Top Rated Car Covers 60 Off on all Outdoor Car Covers, Indoor Car Covers and Waterproof Car Covers Free Shipping, Returns and Lifetime Warranty Call Us Today at 1 800 916 6041.
mohsinkhatri · 67 weeks and 4 days ago
Thank you for very usefull information.. One Bernam price
mohsinkhatri · 66 weeks and 1 day ago
Rice Purity Test is a 100-question survey that assesses the participants’ supposed degree of innocence in worldly matters.
mackpurity · 64 weeks and 6 days ago
Instander APK is a highly sought-after variant of Instagram, but it is not readily available on the Google Play store. To gain access to its additional features, you will need to download this modded version. In this post, I'll outline the steps to download and install Instander APK so that you can make the most out of your Instagram experience.
mackpurity · 64 weeks and 6 days ago
A COC (Clash of Clans) base layout refers to the arrangement of buildings, walls, traps, and defenses in a player's village in the mobile strategy game, Clash of Clans. The layout is designed to protect the player's resources, such as gold, elixir, and dark elixir, from being stolen by enemy players. The base layout also helps to defend against enemy attacks and prevent the destruction of buildings within the player's village. Players can customize their base layout according to their preferred strategy, defensive style, and gameplay goals. https://cocbaselayout.com/
mackpurity · 64 weeks and 6 days ago
De rekenmachine kan als de beste alle basisberekeningen zoals optellen, aftrekken, vermenigvuldigen, delen, worteltrekken en procentberekeningen uitvoeren. https://rekenmachineonline.net/
mackpurity · 64 weeks and 6 days ago
Nagaland State Lottery Sambad (????? ?????) Result Today of Dear Lottery Morning, Day, and Evening / Night Live Ticket Draw on Lottery Sambad. lottery sambad old
mackpurity · 64 weeks and 6 days ago
LibreTube Mod APK is an application for you to watch movies and much other interesting content anonymously and privately. website
mackpurity · 64 weeks and 6 days ago
Dubai's extreme climate makes air con absolutely essential for a cushty living environment. However, AC breakdowns can occur at any time, causing inconvenience and discomfort. That's why it's essential to have a reliable AC repair service in Dubai that will handle any issue quickly and efficiently. In this information, we will discuss why hiring a plumber in Dubai for AC repair is important and how Toolboys can allow you to keep your AC in top condition. Plumber in Dubai
mohsinkhatri · 63 weeks ago
Personally, I have found that to remain probably the most fascinating topics when it draws a parallel to. You may find two to three new levels inside L . a . Weight loss and any one someone is incredibly important. Initial stage may be real melting away rrn the body. lose weight del-cnc.com
jackson2321 · 62 weeks ago
SEO, oftewel zoekmachine optimalisatie, is tegenwoordig onmisbaar voor bedrijven in Alkmaar die online actief zijn. Het is namelijk dÃ© manier om hoger in de zoekresultaten te verschijnen en zo meer potentiÃ«le klanten te bereiken. Maar hoe pak je SEO effectief aan als bedrijf? Het begint bij het optimaliseren van je website en het creÃ«ren van relevante en waardevolle content. Daarnaast is het belangrijk om slim gebruik te maken van zoekwoorden en backlinks. Maar SEO is geen eenmalige actie, het vergt constant onderhoud en optimalisatie. Met de juiste strategie en inzet kan SEO echter zorgen voor een boost in online zichtbaarheid en uiteindelijk ook in omzet. Dus waar wacht je nog op? Start vandaag nog met het verbeteren van je SEO in Noord-Holland-Noord! Als je als bedrijf gevestigd bent in Alkmaar, wil je uiteraard je doelgroep in de postcode regio NHN bereiken. Een manier om dit te doen is door de inzet van zoekmachineoptimalisatie (SEO). Dit zorgt ervoor dat jouw website hoger in Google komt te staan en dat potentiÃ«le klanten sneller bij jou uitkomen. Een marketingbureau kan hierbij helpen door het uitvoeren van een zoekwoordanalyse en het optimaliseren van de content op je website. Zo weet je zeker dat je de juiste doelgroep bereikt en dat je bedrijf daarbij ook nog eens goed opvalt. Internetmarketingbureaus in Alkmaar SEO/SEA
mohsinkhatri · 61 weeks and 6 days ago
Extraordinary things you've generally imparted to us. Simply continue written work this sort of posts.The time which was squandered in going for educational cost now it can be utilized for studies.Thanks visit our products
jackson2321 · 61 weeks and 6 days ago
I wish more authors of this type of content would take the time you did to research and write so well. I am very impressed with your vision and insight. Japanese startups
mohsinkhatri · 61 weeks and 3 days ago
Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me. PikaShow
jackson2321 · 60 weeks and 2 days ago
The Rice Purity Test can also prompt self-reflection and introspection. By answering the questions honestly, individuals may gain insight into their own values, boundaries, and personal growth over time. https://teletype.in/@ricepuritytest/omJGy5yaoYP
Sfroster · 60 weeks and 2 days ago
The Rice Purity Test can also prompt self-reflection and introspection. By answering the questions honestly, individuals may gain insight into their own values, boundaries, and personal growth over time. take rice purity test.
Sfroster · 60 weeks and 2 days ago
This article is an engaging abundance of enlightening information that is intriguing and elegantly composed. I praise your diligent work on this and thank you for this data. You have what it takes to get consideration.  Pinoy Flix
jackson2321 · 60 weeks and 1 day ago
Your content is nothing short of bright in many forms. I think this is friendly and eye-opening material. I have gotten so many ideas from your blog. Thank you so much. h4 led bulb
mohsinkhatri · 56 weeks and 1 day ago
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work. laser cut metal panels
mohsinkhatri · 56 weeks ago
For all the drama enthusiasts out there, I highly recommend checking out DramaCool. Their diverse collection of captivating shows will keep you hooked. Click here to explore their amazing selection and start enjoying your favorite dramas.
dramacoolslv · 55 weeks and 5 days ago
Als ondernemer zijnde is het van belang om je vindbaarheid online te vergroten en meer leads te genereren. Gelukkig kan Httpmarketing je hierbij helpen als online marketing specialist in Zaandam. Door middel van SEO en andere online marketing strategieën zorgt Httpmarketing ervoor dat jouw bedrijf groeit en je doelgroep bereikt wordt. Met hun kennis en ervaring op het gebied van Google en online marketing, weet je zeker dat jouw bedrijf opvalt tussen de concurrentie. Twijfel daarom niet langer en maak gebruik van de expertise van Httpmarketing om jouw bedrijf naar een hoger niveau te tillen. Online Marketing specialist Zaandam
mohsinkhatri · 53 weeks and 6 days ago
Welcome to Dog Car Seat Custom! We're thrilled to have you here and share our passion for keeping your furry friends safe and stylish on the road. Let us tell you a little bit about who we are and what we're all about. https://www.dogcarseatcustom.com/
dogcarseatcustom · 44 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.