NOTE: I'm aware of this question: How to grep-inverse-match and exclude "before" and "after" lines. Mine is not a duplicate as had been previously cited, the answers to that question also deletes the pattern, while in this question the pattern itself must be preserved.
I am trying to delete n lines after a pattern and m lines before a pattern (without deleting pattern). For example, if the file is:
1 2 3 4 5 6 7 8 9
If, Pattern = 5, and n = 2 and m = 3. Then:
1 5 8 9
Could you please suggest how to do this?
Bonus: It would be great if we could set either m or n = 0 in the same code. For example. If we set m=0 and n=1, in the above example, we should get:
1 2 3 4 5 7 8 9