给定月份/年份的最后一个星期六 [英] The last Saturday of a given month / year
本文介绍了给定月份/年份的最后一个星期六的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Unix中,我想查找给定月份和年份中最后一个星期六的日期(月份中的某天).我知道cal
将给我给定月份/年份的日历.获得最后一个星期六的好方法是什么?
In Unix, I want to find the date (day of month) of the last Saturday of a given month and year. I know cal
will give me the calendar for a given month / year. What is a good way to get the last Saturday?
更新:我想要一个可以在一周中的任何一天都可以使用的解决方案.例如,我也可以使用相同的方法来查找最后一个星期日或星期三的日期.
Update: I'd like a solution that I could use to apply to any day of the week. For example, I could use the same method to find the date of the last Sunday or Wednesday as well.
推荐答案
为此使用awk.考虑一下:
Use awk for that. Consider this:
cal 5 2013 | awk 'NF>6{a=$7} END{print a}'
输出:
25
这篇关于给定月份/年份的最后一个星期六的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文