Using the regexp string, how can I remove all the lines before the first line that contains a match? e.g How can I change this:
lost
load
linux
loan
linux
into this:
linux
loan
linux
I tried:
echo "lost
load
linux
loan
linux" | sed -e 's/.*^li.*$//g'
but it returns this, not changing anything:
lost
load
linux
loan
linux
I'd like to make it work so that it won't output anything when there's no match.
Best Answer
One way, POSIXly:
or shorter:
or even shorter:
For readers who wonder why I prefer the longer over the shorter version, the longer version will only perform i/o over the rest of file, while using ranges can affect the performance if the 2nd address is a regex, and the regexes are trying to be matched more than is necessary.
Consider:
with:
you can see the different between two versions. With complex regex, it's will be big difference.