[英]MMDDYYYY date format comparsion in awk
I Just started to use Awk
. 我刚开始使用
Awk
。 Here I include my awk
code which is used for retrieve the names of person who are all born on or before 05171997 这里包含我的
awk
代码,该代码用于检索所有在05171997或之前出生的人的姓名
awk -F "\t" '(substr($2,5,4)<1997||(substr($2,5,4)==1997 && substr($2,1,2)<=05 && substr($2,3,2)<=17)) {print $1}' <input.txt
Data at the input.txt input.txt中的数据
Bharath 01061992
Ragul 10302002
Bala 01171993
Arjun 05142003
Vimal 06301997
Ramesh 05171997
Kamal 05151997
Vinoth 05201997
It just fine for Now. 现在就好了。 I want to know Is there any other best way to compare two dates than my method of comparison?
我想知道除了我的比较方法以外,还有其他最佳方法可以比较两个日期吗?
You can rearrange them into the ISO date format, which can easily be used for arithmetic comparisons. 您可以将它们重新排列为ISO日期格式,可以轻松地用于算术比较。
Assuming you have GNU awk(for gensub). 假设您有GNU awk(用于gensub)。
awk -F'\t' -vdate="19970517" 'date>=gensub(/(....)(....)/,"\\2\\1",1,$2){print $1}' f
produces 产生
Bharath
Bala
Ramesh
Kamal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.