Skip to main content
2 of 4
edited tags
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

Compare dates using awk in bash

I have a file and each line has some info and a date,so what I want is to print the lines with dates after a given date. I use this awk command

sort -t$'|' -k5 $2 | awk -F '|' -v DatedAfter=$4 '!/^#/ && $5>=DatedAfter {print $0}'

While the code works if the dates are DD-MM-YYYY my file's dates are DD/MM/YYYY.

1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer