需要在一年内获得所有星期一的日期 [英] Need to get the dates of all mondays in a year
问题描述
我需要在每周的基础上对数据进行排序,所有这些都是日志文件中的日期。
因此,为了整理每周的数据,我想创建一个列表,其中包含给定年份的所有星期一的日期。我已经尝试了一些工作,而我目前唯一的想法就是使用ncal和年份作为循环遍历所有月份,并提取所有的星期一。是不是有更有效的方式?
要获取所有的星期一,通过获取所有日期和周一过滤: p>
为'seq 0 365'
do date -d+ $ i day
done | grep Mon
当然,你也可以每星期一,持续增加7天。 >
I need to sort data on a weekly base and all i have are dates in a logfile. Therefore to sort out data per week i would like to create a list with the dates of all mondays for a given year. I have tried to work something out and the only idea i currently have is to use ncal with year and month as argument looping over all months and extracting all mondays. Isn't there a more efficient way?
To get all mondays, by getting all dates and filtering by Mondays:
for i in `seq 0 365`
do date -d "+$i day"
done | grep Mon
Of course, you could also take a monday and keep incrementing by 7 days.
这篇关于需要在一年内获得所有星期一的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!