Basically, you can select a range of lines using regexes. For example, if I wanted to get the text under one header in a Markdown document, I could write something like this:
sed -n '/^## Overview/,/^#/ { /^#/b; p }' README.md
- The '-n' flag tells sed not to print all matched lines by default.
- '/^## Overview/,/^#/' is a range address that matches all lines from
one starting with "## Overview" to another line starting with "#", inclusive.
- '{ /^#/b; p }' is a command group that's executed for each matched line.
- '/^#/b' uses the 'b' (branch) command to skip lines starting with "#" to
avoid printing the header lines, which are included in the range.
- Finally, 'p' is the print command, which tells sed to print all the other
lines.
That said, I mainly read it because I've always used things like Bash's built-in parameter expansion[1] and regex capability[2] instead of sed, and I mostly think I confirmed that bias. I'll probably turn to sed for certain string manipulations from now on, but I'm not sure I'll be using it a whole lot more often.[0] https://www.gnu.org/software/sed/manual/sed.html#sed-address... [1] https://wiki.bash-hackers.org/syntax/pe [2] https://www.linuxjournal.com/content/bash-regular-expression...