Using awk
or sed
how can I select lines which are occurring between two different marker patterns? There may be multiple sections marked with these
Using sed
:
sed -n -e '/^abc$/,/^mno$/{ /^abc$/d; /^mno$/d; p; }'
The -n
option means do not print by default.
The pattern looks for lines containing just abc
to just mno
, and then executes the actions in the { ... }
. The first action deletes the abc
line; the second the mno
line; and the p
prints the remaining lines. You can relax the regexes as required. Any lines outside the range of abc
..mno
are simply not printed.