-2

This question already has an answer here:

A script that should look out for texts with a date inside the file thats 30 days older than the current date then move to another file like the $ awk '$NF <= "2018-05-01"' ip.txt but need a command to get text with dates 30 days older than the system current date automatically without having to manually change the script everyday

marked as duplicate by G-Man, Ipor Sircer, muru, Rui F Ribeiro, Jeff Schaller Dec 18 '18 at 10:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • A script that should look out for texts with a date inside the file thats 30 days older than the current date then move to another file like the $ awk '$NF <= "2018-05-01"' ip.txt but need a command to get text with dates 30 days older than the system current date automatically without having to manually change the script everyday – Kasiiku Mark Dec 19 '18 at 6:10
0

cmd:

for i in {1..30}; do date +%Y-%m-%d -d "$i day ago"; done >outputfile

output:

 cat outputfile
2018-12-17
2018-12-16
2018-12-15
2018-12-14
2018-12-13
2018-12-12
2018-12-11
2018-12-10
2018-12-09
2018-12-08
2018-12-07
2018-12-06
2018-12-05
2018-12-04
2018-12-03
2018-12-02
2018-12-01
2018-11-30
2018-11-29
2018-11-28
2018-11-27
2018-11-26
2018-11-25
2018-11-24
2018-11-23
2018-11-22
2018-11-21
2018-11-20
2018-11-19
2018-11-18
  • $ cat ip.txt Blah blah blah 2018-12-13 Blah blah blah 2018-02-13 Blah blah blah 2018-05-01 $ awk '$NF < "2018-05-01"' ip.txt Blah blah blah 2018-02-13 if possible similar to that without having to manually input the current date as shown in the 2018-05-01 but automatically system date – Kasiiku Mark Dec 19 '18 at 6:43

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