亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2972 | 回復(fù): 5
打印 上一主題 下一主題

[文本處理] 截取時間段和轉(zhuǎn)化為時間戳 [復(fù)制鏈接]

論壇徽章:
20
卯兔
日期:2015-01-26 22:05:142015亞冠之薩濟拖拉機
日期:2015-09-10 15:15:282015亞冠之阿爾希拉爾
日期:2015-09-25 17:37:53程序設(shè)計版塊每日發(fā)帖之星
日期:2015-10-03 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-09 06:20:00CU十四周年紀(jì)念徽章
日期:2015-12-17 09:07:15程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:34程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:34程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:342015亞冠之廣州富力
日期:2015-08-27 19:29:56每日論壇發(fā)貼之星
日期:2015-08-26 06:20:002015亞冠之阿爾希拉爾
日期:2015-05-18 17:26:27
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-04-09 00:13 |只看該作者 |倒序瀏覽
請教大神一個問題:
輸入:
Apr 07, 2015 6:13:30 PM org.apache.coyote.http11.AbstractHttp11Processor endRequest

輸出:
Apr 07, 2015 6:13:30 PM

要求:
用awk怎么截取到行首到PM或AM為止的時間,并將該時間段轉(zhuǎn)化為時間戳1428401610,不能在awk里調(diào)用date命令

論壇徽章:
145
技術(shù)圖書徽章
日期: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技術(shù)圖書徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
2 [報告]
發(fā)表于 2015-04-09 01:37 |只看該作者
回復(fù) 1# songyc_2015

mktime(datespec)

    Turn datespec into a timestamp in the same form as is returned by systime(). It is similar to the function of the same name in ISO C. The argument, datespec, is a string of the form "YYYY MM DD HH MM SS [DST]". The string consists of six or seven numbers representing, respectively, the full year including century, the month from 1 to 12, the day of the month from 1 to 31, the hour of the day from 0 to 23, the minute from 0 to 59, the second from 0 to 60,54 and an optional daylight-savings flag.

    The values of these numbers need not be within the ranges specified; for example, an hour of -1 means 1 hour before midnight. The origin-zero Gregorian calendar is assumed, with year 0 preceding year 1 and year -1 preceding year 0. The time is assumed to be in the local timezone. If the daylight-savings flag is positive, the time is assumed to be daylight savings time; if zero, the time is assumed to be standard time; and if negative (the default), mktime() attempts to determine whether daylight savings time is in effect for the specified time.

    If datespec does not contain enough elements or if the resulting time is out of range, mktime() returns -1.
   

論壇徽章:
5
未羊
日期:2014-08-04 16:15:21天秤座
日期:2014-08-13 13:52:372015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:112015亞冠之浦和紅鉆
日期:2015-06-29 15:30:48
3 [報告]
發(fā)表于 2015-04-09 09:22 |只看該作者
  1. awk -F "[ ,:]+" '{if($1~/Apr/)$1="04";if($1~/Jan/)$1="01";if($4~/^.$/)$4="0"$4;print strftime("%s",mktime($3" "$1" "$2" "$4" "$5" "$6))}'
復(fù)制代碼
例子里懶得寫那么多$1的月份匹配了,反正都一樣LZ自己補齊就是了

論壇徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16賽季CBA聯(lián)賽之北京
日期:2016-07-06 15:42:0715-16賽季CBA聯(lián)賽之同曦
日期:2016-06-12 10:38:0915-16賽季CBA聯(lián)賽之佛山
日期:2016-05-27 11:54:56黃金圣斗士
日期:2015-12-02 11:44:35白銀圣斗士
日期:2015-11-25 14:32:43白銀圣斗士
日期:2015-11-23 12:53:352015亞冠之布里斯班獅吼
日期:2015-10-21 16:55:482015亞冠之首爾
日期:2015-09-01 16:46:052015亞冠之德黑蘭石油
日期:2015-08-31 11:39:192015亞冠之薩濟拖拉機
日期:2015-08-28 21:06:5315-16賽季CBA聯(lián)賽之廣東
日期:2016-07-12 14:58:53
4 [報告]
發(fā)表于 2015-04-09 10:04 |只看該作者
  1. awk 'BEGIN{
  2.     a["Jan"]=01
  3.     a["Feb"]=02
  4.     a["Mar"]=03
  5.     a["Apr"]=04
  6.     a["May"]=05
  7.     a["Jun"]=06
  8.     a["Jul"]=07
  9.     a["Aug"]=08
  10.     a["Sep"]=09
  11.     a["Oct"]=10
  12.     a["Nov"]=11
  13.     a["Dec"]=12
  14.     FS="[ :,]+"
  15. }{
  16.     if($7=="PM") $4=$4+12
  17.     print mktime($3" "a[$1]" "$2" "$4" "$5" "$6)
  18. }
  19. ' file
復(fù)制代碼

論壇徽章:
28
2015年迎新春徽章
日期:2015-03-04 10:16:53午馬
日期:2015-03-20 17:11:07亥豬
日期:2015-03-20 17:11:23戌狗
日期:2015-03-20 17:11:33酉雞
日期:2015-03-20 17:11:47申猴
日期:2015-03-20 17:11:58未羊
日期:2015-03-20 17:12:10子鼠
日期:2015-03-20 17:12:23丑牛
日期:2015-03-20 17:12:40卯兔
日期:2015-03-20 17:12:51辰龍
日期:2015-03-20 17:13:00巳蛇
日期:2015-03-20 17:13:12
5 [報告]
發(fā)表于 2015-04-09 16:07 |只看該作者
  1. echo "Apr 07, 2015 6:13:30 PM org.apache.coyote.http11.AbstractHttp11Processor endRequest"|awk -F'[,: ]' -vT="Jan|Feb|Mar|Apr|May|June|July|Aug|Sep|Oct|Nov|Dec" 'function m (x,y) {for(i=0;i<x;i++)y="0"y;return y}BEGIN{split(T,a,"|");for(;j++<12;){b[a[j]]=m(1-(j/10),j)}}{$5=$8=="AM"?$5:($5+12);c=$4" "b[$1]" "$2" "$5" "$6" "$7;print mktime(c)}' inputfile
復(fù)制代碼

論壇徽章:
20
卯兔
日期:2015-01-26 22:05:142015亞冠之薩濟拖拉機
日期:2015-09-10 15:15:282015亞冠之阿爾希拉爾
日期:2015-09-25 17:37:53程序設(shè)計版塊每日發(fā)帖之星
日期:2015-10-03 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-09 06:20:00CU十四周年紀(jì)念徽章
日期:2015-12-17 09:07:15程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:34程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:34程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:342015亞冠之廣州富力
日期:2015-08-27 19:29:56每日論壇發(fā)貼之星
日期:2015-08-26 06:20:002015亞冠之阿爾希拉爾
日期:2015-05-18 17:26:27
6 [報告]
發(fā)表于 2015-04-10 00:15 |只看該作者
感謝樓上各位大神指導(dǎo)
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP