- 论坛徽章:
- 145
|
回复 1# 毛线浅爱
>>想将该文件的第四列 的时间 减去第三列的时间 时间差变换成天数 输出到第五列中...
What You Think Is What You Code(WYTIWYC)
$ awk 'function diffday(s,e){return(int((sec(e)-sec(s))/86400))}function sec(str){gsub(/../,"& ",str);sub(/ /,"",str);return(mktime(str))}BEGIN{FS=OFS="|"}{$5=diffday($3,$4)}1' FILE
13400041414|18702652237|20150302131949|20150302132312|0
13400041414|15052124614|20150107111304|20150302131709|54
13400041414|18279684920|20150302133159|20150313092141|10
13400041414|14779568524|20150316062001|20150316063117|0
13400041414|15103434017|20150119152514|20150313092146|52
13400041414|18479343074|20150316061904|20150316062042|0
13400041414|13405761414|20150316063544|20150316063639|0
13400041414|18870680194|20150316060912|20150316061428|0
13400041414|14762010034|20150105110754|20150115104932|9
13400041414|15152494334|20141230100609|20141230101153|0
13400643973|13400644513|20150515154622|20150515155231|0
13400644913|13489937792|20150519111937|20150609144721|21
Note: https://www.gnu.org/software/gawk/manual/gawk.html#Time-Functions
mktime(datespec)
Turn datespec into a timestamp in the same formas is returned by systime(). It is similar to the function of thesame 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 monthfrom 1 to 31, the hour of the day from 0 to 23, the minute from 0 to59, the second from 0 to 60,53and an optional daylight-savings flag.
|
|