1

So I have a list of dates and I need to develop a script that keeps a rolling count of how many dates are older than 14 days (date --date="14 days ago" +%Y%m%d). Not sure how I can have the date check through a file. Most of the research I find shows me how to come timestamps, which is not what I'm trying to accomplish.

20160517
20160518
20160519
20160520
20160521
20160522
20160523
20160524
20160525
20160526
20160527
20160528
20160529
20160530
20160531
20160601
20160602
20160603
20160604
20160605
20160612
20160612
20160615
20160615
20160615
20160615
20160615
20160615
4

Assuming there's a file called dates containing the list of dates, one per line (and nothing else), something like this might work to count the ones older than 14 days:

$ date=$(date --date="14 days ago" +%Y%m%d)
$ awk '($0 < "'$date'") {count += 1} END {print count}'  < dates
20

(Given they are in yyyymmdd format, the comparison is easy.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.