Delete records that do not belong to that day

i have a requirement to delete records that do not belong to that day. For example in a file that came on July 31st ,2018 there are records that belong to Aug 1st,2018 as well and I want to find and delete those records. I want to delete anything with 01-Aug-2018 . I have several files like that. I need a script that gets the first line second column that is date and add one day to it and delete that record.in this case all 1st Aug records should be deleted. Thank you in advance for your help.

a,31-Jul-2018 12:00,14
a,31-Jul-2018 12:01,13
a,31-Jul-2018 12:02,15
a,31-Jul-2018 12:03,19
and so on 
.
.
a,31-Jul-2018 11:59,6  
a,01-Aug-2018 12:00,9
b,31-Jul-2018 12:00,7 
b,31-Jul-2018 12:01,7
b,31-Jul-2018 12:02,6
b,31-Jul-2018 12:03,3
and so on 
.
.
b,31-Jul-2018 11:59,8  
b,01-Aug-2018 12:00,9
c,31-Jul-2018 12:00,7
c,31-Jul-2018 12:01,7
c,31-Jul-2018 12:02,6
 c,31-Jul-2018 12:03,8

Can you post what you've tried to solve this...and what about records that are less than the current date

1 Like

Thank you for looking into this. There will not be records that are less than the date you see in the first row. july 1st file will have july first records and few records with july 2 and i want to delete those july 2 second records. I just tried awk by googling

awk -F ',' '{print $3}' file1.txt

that gets the first date and i dont know how to add one day to it and delete those records correspoding to it.

The possible solutions highly depend on the OS, shell, and tools' (e.g. date or awk ) versions that you use. So please post this info.

this is our linux version 2.6.32-696.10.1.el6.x86_64.

Try

awk -F, 'NR == 1 {("date -d\"" $2 "+1day\" +\"%d-%b-%Y\"") | getline DT} $2 !~ DT' file
a,31-Jul-2018 12:00,14
a,31-Jul-2018 12:01,13
a,31-Jul-2018 12:02,15
a,31-Jul-2018 12:03,19
and so on 
.
.
a,31-Jul-2018 11:59,6  
b,31-Jul-2018 12:00,7 
b,31-Jul-2018 12:01,7
b,31-Jul-2018 12:02,6
b,31-Jul-2018 12:03,3
and so on 
.
.
b,31-Jul-2018 11:59,8  
c,31-Jul-2018 12:00,7
c,31-Jul-2018 12:01,7
c,31-Jul-2018 12:02,6
c,31-Jul-2018 12:03,8
1 Like

Thank you works perfectly appreciate your quick response