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 *5*and the remaining lines. If my file contains no *5*, I need to do have the remaining lines till the end. **NOTE:** I saw the referenced link that looks like a duplicate to my question, titled: [Show only text between 2 matching pattern](https://unix.stackexchange.com/questions/17404/show-only-text-between-2-matching-pattern) but it doesn't answer my question. The answers there didn't include a way to handle if the secondmatch isn't in the file.