Some less than simple sed statements
stuff | sed -n '/pattern1.*/b remove
b next
:remove
# Load a second long
N
# Remove the first line, I have already eliminated it
s|.*\n||
# Repeat if it matches pattern 2
/^pattern2/b remove
# Path for printing normal lines
:next
p'Example:
echo "ok
1
foo2 222
3
4
foo1 111
foo2 234
foo2 3
foo2 4
foo2 5
5
foo2
6
foo2" | sed -n '/foo1.*/b remove
b next
:remove
# Load a second long
N
# Remove the first line, I have already eliminated it
s|.*\n||
# Repeat if it matches pattern 2
/^foo2/b remove
# Path for printing normal lines
:next
p'sed '/pattern1/,/pattern2/{//!d;}'Example
echo "ok
1
foo2 222
3
4
foo1 111
foo2 234
foo2 3
foo2 4
foo2 5
5
foo1
6
foo2" | sed '/foo1/,/^[^f]/{//!d;}; /foo1/d'The extra /foo1/d will remove foo1 too, so it can be partially inclusive if you want
The other patterns from https://stackoverflow.com/a/46434705/4166604 were all greedy on the second pattern
sed '1,/pattern/s/pattern/replace/'
#shortcut
sed '1,/pattern/s//replace/'From: https://stackoverflow.com/a/46434705/4166604
sed -n -e '/b/,/d/!p' abcde=> aesed -n -e '/b/,/d/p' abcde=> bcdsed -n -e '/b/,/d/{//!p}' abcde=> csed -n -e '/b/,/d/{//p}' abcde=> bdsed -e '/b/,/d/!d' abcde=> bcdsed -e '/b/,/d/d' abcde=> aesed -e '/b/,/d/{//!d}' abcde=> abdesed -e '/b/,/d/{//d}' abcde=> ace