Skip to main content
7 of 9
added 148 characters in body
Ramesh
  • 40.6k
  • 45
  • 149
  • 222

sed lines after match and before next match

How to get all the lines after a matching word till the next different matching word?

For example, my input looks like below.

1 2 3 5 6 

and I need to sed from 1 to 5 and in my output I need to include 1 but I do not want to include 5and the remaining lines.

If my file contains no 5, I need to do have the remaining lines till the end.

I saw the referenced link but it doesn't answer my question.