I have a text formatted like the following:
2020-05-02
apple
string
string
string
string
string
2020-05-03
pear
string
string
string
string
string
2020-05-03
apple
string
string
string
string
string
Each group has 7 lines = Date, Fruit and then 5 strings.
I would like to delete groups of 7 lines from the file by supplying just the date and the fruit.
So if choose '2020-05-03' and 'pear'
this would remove:
2020-05-03
pear
string
string
string
string
string
from the file, resulting in this:
2020-05-02
apple
string
string
string
string
string
2020-05-03
apple
string
string
string
string
string
The file contains thousands of lines, I need a command, probably using sed or awk to:
Search for date
2020-05-03Check if string after date is
peardelete both lines and following
5lines
I know i can delete with sed like sed s'/string//g', however i am not sure if i can delete multiple lines.
Note: Date followed by fruit is never repeated twice so
2020-05-02
pear
would only occur once in the file
How can i acheive this?
2020-05-03\npear\n(?:.*\n){5}2020-05-03\npear\n.*\n.*\n.*\n.*\n.*\n