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. I saw the referenced [link](http://unix.stackexchange.com/questions/17404/show-only-text-between-2-matching-pattern) but it doesn't answer my question.