Delete lines with a date older than a week old.
-
Fellow Notepad++ Users,
Could you please help me with the following search-and-replace problem I am having?
I want to delete all lines with dates older than a week old.
,0627,297,07/21/22 05:43 AM,322400-
,0712,19273,07/06/22 12:05 PM,713020-
,0713,2958,04/19/22 11:43 AM,714000-
,0714,12908,07/19/22 05:14 PM,732000-Here is how I would like the data to look.
,0627,297,07/21/22 05:43 AM,322400-
,0714,12908,07/19/22 05:14 PM,732000-To accomplish this, I have tried using the following Find/Replace expressions and settings.
I have found no help from someone doing this.
Thank you.
-
Is there any reason you just didn’t continue posting to THIS thread?
-
-
@Dennis-Prather said in Delete lines with a date older than a week old.:
I have tried using the following Find/Replace expressions and settings.
It cannot be done this way, because how are you going to tell Find/Replace what “a week” means?
And why did you say “following” when nothing follows?
-
Here’s a simple PythonScript that seems to accomplish the goal:
# -*- coding: utf-8 -*- from __future__ import print_function from Npp import * import datetime as dt import time #------------------------------------------------------------------------------- class T23284(object): def __init__(self): date_current = dt.datetime(*time.localtime()[:6]) def replace_func(m): date_in_question = dt.datetime(*time.strptime(m.group(1), '%m/%d/%y')[:6]) return '' if (date_current - date_in_question).days > 7 else m.group(0) editor.rereplace(r'(?-s)^,\d*?,\d*?,(\d{2}/\d{2}/\d{2}).*(\R|\z)', replace_func) #------------------------------------------------------------------------------- if __name__ == '__main__': T23284()
-
Thank You ill give it a try.