cat grab.txt
My Dashboard
Fnfjfjf. random test
00:50
1:01:56
My Notes
No data found.
Change Language + English
Submit
Estimation of Working Capital Lecture 1
Estimation of Working Capital Lecture 2
Estimation of Working Capital Lecture 3
Money Market Lecture 254
Money Market Lecture 255
Money Market Lecture 256
International Trade Lecture 257
International Trade Lecture 258
International Trade Lecture 259
Terms And Conditions
84749473837373
Random text fifjfofifofjfkfkf
I need to filter this text after doing the following
- Delete all lines before the first occurrence of word - Lecture
- Delete all lines after the last occurrence of word - Lecture
- Remove all empty lines
Expected output
Estimation of Working Capital Lecture 1
Estimation of Working Capital Lecture 2
Estimation of Working Capital Lecture 3
Money Market Lecture 254
Money Market Lecture 255
Money Market Lecture 256
International Trade Lecture 257
International Trade Lecture 258
International Trade Lecture 259
What have I tried so far?
cat grab.txt | sed -r '/^\s*$/d; /Lecture/,$!d'
After searching for a bit and some trial-error, I am able to remove empty lines and remove all lines before the first occurrence but unable to remove all lines after the last occurrence.
Note - Even tho my existing command is using sed, its fine if the answer is in awk, perl or grep