Artificial intelligent assistant

Remove above line if matched keyword is found I have a data something like this: Amit: Mem 30 40 50 Sumit: Mem 50 70 80 Tarun: Nishant: Mem 90 20 45 As in "Tarun:",Mem is not present need to remove it. final output should be Amit: Mem 30 40 50 Sumit: Mem 50 70 80 Nishant: Mem 90 20 45 Please help me to get this resolve. I have tried but not able to get the required output

$ sed '$!N;/\
Mem/p;D' file
Amit:
Mem 30 40 50
Sumit:
Mem 50 70 80
Nishant:
Mem 90 20 45


* `$!N`: For every line that is not the last line, append the next line to the buffer with a delimiting newline in-between.

* `/\
Mem/p`: If the buffer now contains a newline character immediately followed by the string ` Mem` (two spaces and `Mem`), then print the buffer. You may also use `[[:blank:]]*` in place of the two spaces to allow for any amount of spaces or tabs at the start of the `Mem` lines.

* `D`: Delete the data in the buffer up to and including the first newline character, and start the next cycle.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 99512c03cdffbf897db08c52ecfae414