I Just started to use 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 -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
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.
Assuming you have GNU awk(for gensub).
awk -F'\t' -vdate="19970517" 'date>=gensub(/(....)(....)/,"\\2\\1",1,$2){print $1}' f
produces
Bharath
Bala
Ramesh
Kamal
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.