I have a file that contains various dates and IPs that I need to do a daily purge of. The file format is:
# 2018-02-21 11:31:37 - user1 - This is a test. 220.127.116.11 # 2018-02-21 11:32:30 - user1 - This is also a test. 18.104.22.168 # 2018-03-06 21:12:44 - user2 - Another comment. 22.214.171.124
On a daily basis I want to remove any comment line + the IP below it that is older than 30 days. For that, I can easily do a bash variable of "LAST_MONTH=
date --date="-30 days" +%Y-%m-%d" and I can get the lines easily enough by doing "DELETE=$(cat /var/www/html/ips | grep $DATE -A1)".
From here, I could technically use sed to wipe out the lines such as "sed -i "s/$DELETE/test/g" "$FILE"" but there are hash tags and multiple lines involved so it's not really working for me right now.
What would you recommend as the best way to do this? I don't want to create another temp file if at all possible. I'd also be interested in both bash and Python solutions.