Bash: output all lines before/after line identified by regex

If you need to output only lines before (or after) a unique line identified by a regular expression, then here are examples of using sed.  All examples in this article can be found in github.

Consider the following lines of content in the variable “$lines”

$ echo "$lines"
ape swings
frog jumps logs
dog barks at squirrels
bear roars
zebra grazes

Lines only after the line starting with “dog” can be output:

echo "$lines" | sed '0,/^dog.*/d'

And lines only before the line starting with “dog” can be output:

echo "$lines" | sed '/^dog.*/q' | head -n -1

REFERENCES

https://unix.stackexchange.com/questions/56429/how-to-print-all-lines-after-a-match-up-to-the-end-of-the-file

catonmat.net, sed one-liners explained

 

NOTES

Alternate way of showing lines only after regex

sed -n '/^dog 123 4335$/ { :a; n; p; ba; }' infile