Bash UNIX中带awk的日期
我想将用户()的两个日期作为参数 因此,我使用awk命令如下:Bash UNIX中带awk的日期,bash,date,unix,awk,Bash,Date,Unix,Awk,我想将用户()的两个日期作为参数 因此,我使用awk命令如下: awk -F'|' '{print $4} [ file ... ] 约会。。如何使用awk将日期从txt格式转换为秒格式?如果日期变量的格式相同,则可以将所有内容转换为数字并使用比较 awk -F'|' -v from=$dateA -v to=$dateB '{gsub("-","",$5); gsub("-","",from); gsub("-","",to)} from &
awk -F'|' '{print $4} [ file ... ]
约会。。如何使用awk将日期从txt格式转换为秒格式?如果日期变量的格式相同,则可以将所有内容转换为数字并使用比较
awk -F'|' -v from=$dateA -v to=$dateB '{gsub("-","",$5);
gsub("-","",from); gsub("-","",to)}
from <= $5 && $5 <= to' file
awk-F'|'-v from=$dateA-v to=$dateB'{gsub(“-”,”,$5);
gsub(“-”,from);gsub(“-”,to)}
从可以通过system()
调用/bin/date+%s”--date=“DATESTRING”
,如果DATESTRING与格式匹配“/bin/date”可以理解,或者使用内部mktime()函数。但是,您需要根据awk(1)划分日期:
因此,您需要准备日期字段以使用文档中给出的表单
split($5, D, "-");
DS = sprintf("%4d %2d %2d 00 00 00", D[1], D[2], D[3]);
T = mktime(DS);
我应该做这项工作。好的,我明白你的意思,但是在比较之后我如何打印整行内容呢?就这样。默认情况下,它将打印满足条件的行。修复了日期变量名。我有以下代码:dateA=date-d“$2”+%Y%m%d dateB=date-d“$4”+%Y%m%d awk-F'|'-v from=$dateA-v to=$dateB'{gsub(“-”,“”,$5);gsub(“-”,“”,dateA);gsub(“-”,“”,dateB)}从我糟糕的、混淆的变量名,应该在代码中使用awk变量from,to。现在修好了。
awk -F'|' -v from=$dateA -v to=$dateB '{gsub("-","",$5);
gsub("-","",from); gsub("-","",to)}
from <= $5 && $5 <= to' file
mktime(datespec)
Turn datespec into a time stamp of the same form as returned by systime(), and return the result. The datespec is a string of
the form YYYY MM DD HH MM SS[ DST]. The contents of the string are 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, and an optional daylight saving 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 saving flag is
positive, the time is assumed to be daylight saving time; if zero, the time is assumed to be standard time; and if negative (the
default), mktime() attempts to determine whether daylight saving 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.
split($5, D, "-");
DS = sprintf("%4d %2d %2d 00 00 00", D[1], D[2], D[3]);
T = mktime(DS);