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'