I have a log file that is a list of repeating characteristics. For example:
## This is the pattern of lines
time
urgency
icon_path
summary
body
appname
## Below is what the log file would actually look like
12:30
critical
test notification
notification
notify-send
11:00
low
earlier notification
notification
notify-send
10:46
normal
hello
world
dunstify
I'm trying to find a way to search for a block/cluster of lines that match my search terms and then delete them in bash. As you can see in the above example, sometimes lines are empty, sometimes they are filled. The best "solution" I have found so far is to use sed '/12:30/,+5 d'
or slightly better sed '/12:30/,/notify-send/d'
. The problem with both of these is that the first one will delete all occurrences of the timestamp, thus deleting more than just one log entry; the problem with the other command is that if there are two or more entries with the same time and appname, all matching entries will get deleted.
What I've been trying to get working and have been failing spectacularly is to do something like: sed '/12:30\n^.*$\n^.*$\ntest notification\nnotification\nnotify-send/d' /tmp/notification_log
. Note that the 2nd and 3rd lines can be anything (the urgency and icon_path lines respectively), which is why I used ^.*$
(to be frank, I'm not even sure if that is the proper regex).
EDIT: Using the above failed command, I would expect the output to be:
11:00
low
earlier notification
notification
notify-send
10:46
normal
hello
world
dunstify
That command had the input of:
12:30
*anything*
*anything*
test notification
notification
notify-send