This is easy to do clearly in awk:
echo "lost
load
linux
loan
linux" | awk '
/^li/ { found = 1 }
found { print }'
Here found is a variable,
with an arbitrarily chosen, self-explanatory name.
It gets set when the program encounters an input line
that matches the regexp.
(Variables initially default to null,
which is functionally equivalent to 0 or FALSE.)
So input lines are printed after the ^li pattern is matched,
and not before.
The third line of the input (the first linux line) is printed
because the conditional print statement comes after
the statement that looks for the pattern and sets the flag.
If you want to start printing with the fourth line
(the line after first linux line),
just reverse the order of the two statements.
If no input line matches the regexp,
the flag never gets set, and nothing is printed.
As I said, the name of the flag variable is arbitrary;
you can use something shorter (e.g., f) if you want.
And { print } is the default action, so you can leave it out.
So, if you don't care about clarity, you can shorten the above to
echo "lost
load
linux
loan
linux" | awk '/^li/{f=1}f'
sed -e '/linux/{:1;n;b1};d'. You can see, inside the curly brace is just a loop, executencommand till the end of file. I broke it into many pieces for POSIX compliant. – cuonglm Jan 24 '16 at 15:22ddelete all before entering the loop when it's placed at the end of the code? And thedcommand usually deletes only the matching part, right? e.g.sed '/linux/d'Why can it delete all in this case? Sorry if this is a stupid question. – stacko Jan 24 '16 at 18:31nisnt for printing pattern space (though it does happen by default) thenoverwrites pattern space w/ the next input line if any. – mikeserv Jan 24 '16 at 19:46delete the lines. You don't have to usedelete command associate with a pattern, you can simplesed dto delete all lines. – cuonglm Jan 25 '16 at 01:34