免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2412 | 回复: 6
打印 上一主题 下一主题

[文本处理] 知道日期/星期,不知道年份,求助 [复制链接]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-08-04 21:25 |只看该作者 |倒序浏览
时间求助:
已知一段文本:
Mon Aug   4  16:02:50   
Fri    Mar  22 17:14:41
Tue Oct   23 18:38:49   
。。。

不知道每列年份是多少,只知道这几个时间发生在[2012,2014]年之间,希望把年份添加到每类的后面
得到的结果是:
Mon Aug   4  16:02:50     2014
Fri    Mar  22 17:14:41     2013
Tue Oct   23 18:38:49      2012
。。。                             。。。

特求助。




论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2014-08-04 21:45 |只看该作者
本帖最后由 volwang 于 2014-08-04 21:46 编辑

可能出现的日期简写:
星期一: Mon
星期二: Tue
星期三:Wed
星期四:Thu
星期五:  Fri
星期六:  Sat
星期天: Sun

一  月:Jan
二  月:Feb
三  月:Mar
四  月:Apr
五  月:May
六  月:Jun
七  月:Jul
八  月:Aug
九  月:Sep
十  月:Oct
十一月:Nov
十二月:Dec

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
3 [报告]
发表于 2014-08-04 21:46 |只看该作者
本帖最后由 jason680 于 2014-08-04 21:54 编辑

回复 1# volwang

1. to get weekday idea
  date -d " Aug 4 2012 16:02:50" +%a

2. awk implement
  cmd="shell command"
  cmd | getline w
  close(cmd)

$ awk -vs=" " '{for(n=2012;n<=2014;n++){cmd="date -d \""$2s$3s n s$4"\" +%a" ;cmd|getline w;close(cmd);if(w==$1){print $0"\t"n;next}}}' FILE
Mon Aug   4 16:02:50           2014
Fri Mar  22 17:14:41        2013
Tue Oct  23 18:38:49        2012

   

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2014-08-04 21:48 |只看该作者
相同日期,星期  ,不同的年份,重复的概率有多大。要是把范围放大,代码是不是可能出错

论坛徽章:
32
处女座
日期:2013-11-20 23:41:20双子座
日期:2014-06-11 17:20:43戌狗
日期:2014-06-16 11:05:00处女座
日期:2014-07-22 17:30:47狮子座
日期:2014-07-28 15:38:17金牛座
日期:2014-08-05 16:34:01亥猪
日期:2014-08-18 13:34:25白羊座
日期:2014-09-02 15:03:55金牛座
日期:2014-11-10 10:23:58处女座
日期:2014-12-02 09:17:52程序设计版块每日发帖之星
日期:2015-06-16 22:20:002015亚冠之塔什干火车头
日期:2015-06-20 23:28:22
5 [报告]
发表于 2014-08-04 22:29 |只看该作者
回复 3# jason680

这头像好牛X~
   

论坛徽章:
33
荣誉会员
日期:2011-11-23 16:44:17天秤座
日期:2014-08-26 16:18:20天秤座
日期:2014-08-29 10:12:18丑牛
日期:2014-08-29 16:06:45丑牛
日期:2014-09-03 10:28:58射手座
日期:2014-09-03 16:01:17寅虎
日期:2014-09-11 14:24:21天蝎座
日期:2014-09-17 08:33:55IT运维版块每日发帖之星
日期:2016-04-17 06:23:27操作系统版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-24 06:20:0015-16赛季CBA联赛之天津
日期:2016-05-06 12:46:59
6 [报告]
发表于 2014-08-05 08:19 |只看该作者
回复 4# volwang
是的. 会有很大的重复率.

所以, 我真心觉得, 靠猜来解决问题不是办法. 你最好能找到更合适的办法.

   

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
7 [报告]
发表于 2014-08-05 08:49 |只看该作者
The 400-year cycle of the Gregorian calendar has 146,097 days and hence exactly 20,871 weeks. So, for example, the days of the week in Gregorian 1603 were exactly the same as for 2003. The years that are divisible by 400 begin on a Saturday. In the 400-year cycle, more months begin on a Sunday (and hence have Friday the 13th) than any other day of the week (see above under Week for a more detailed explanation of how this happens). 688 out of every 4800 months (or 172/1200) begin on a Sunday, while only 684 out of every 4800 months (171/1200) begin on each of Saturday and Monday, the least common cases.

A smaller cycle is 28 years (1,461 weeks), provided that there is no dropped leap year in between. Days of the week in years may also repeat after 6, 11, 12, 28 or 40 years. Intervals of 6 and 11 are only possible with common years, while intervals of 28 and 40 are only possible with leap years. An interval of 12 years only occurs with common years when there is a dropped leap year in between.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP