sed '/if-the-pattern-space-has-this/<do this command>' <file>
sed '/if-the-pattern-space-has-this/<do this command>' <file>
> sed -n '/good-pattern/q 0;$q 1' <<< "bad-pattern"
> echo $?
1
> sed -n '/good-pattern/q 0;$q 1' <<< "good-pattern"
> echo $?
0
> sed -n '/good-pattern/q 0;$q 1' <<< "bad-pattern"
> echo $?
1
> sed -n '/good-pattern/q 0;$q 1' <<< "good-pattern"
> echo $?
0
sed -n '/^block:/,/^$/{/crazy/q 0};$q 1' <<END && echo -e "\n--------------\n FOUND" || echo "\n----------------\n NOT FOUND"
this thing
block:
   is crazy
END
--------------
 FOUND
sed -n '/^block:/,/^$/{/crazy/q 0};$q 1' <<END && echo -e "\n--------------\n FOUND" || echo "\n----------------\n NOT FOUND"
this thing
block:
   is crazy
END
--------------
 FOUND
> sed -n '/^block:/,/^$/{/crazy/q 0};$q 1' <<END && echo -e "\n--------------\n FOUND" || echo -e "\n----------------\n NOT FOUND"
this thing
block:
   is crazy
END
----------------
 NOT FOUND
> sed -n '/^block:/,/^$/{/crazy/q 0};$q 1' <<END && echo -e "\n--------------\n FOUND" || echo -e "\n----------------\n NOT FOUND"
this thing
block:
   is crazy
END
----------------
 NOT FOUND
# Searching for the word "crayons", replace this
# with "pizza" to see a positive match.  The replacement
# word is "meanies", which you can also replace.
s/crayons/meanies/
# We print each line regardless of a pattern match
p
# If the most recent 's' command did a substitution, take
# the branch to the loop.
t loop
# If we're not on the last line, delete the pattern space and
# start processing the next line.
$!d
# This only happens on the last line.  If we get here, swap the
# last hold space in and then return positive or negative based
# on the content in the hold space.  The hold space should only
# have matching content if we matched once before and swapped
# the matching pattern into the hold space.
x
/meanies/q 0
# If we don't match the replacement pattern then return falsy.
q 1
# This loop is only taken on a positive match, effectively
# just swapping the most recent match into the hold space.
:loop
x
# Searching for the word "crayons", replace this
# with "pizza" to see a positive match.  The replacement
# word is "meanies", which you can also replace.
s/crayons/meanies/
# We print each line regardless of a pattern match
p
# If the most recent 's' command did a substitution, take
# the branch to the loop.
t loop
# If we're not on the last line, delete the pattern space and
# start processing the next line.
$!d
# This only happens on the last line.  If we get here, swap the
# last hold space in and then return positive or negative based
# on the content in the hold space.  The hold space should only
# have matching content if we matched once before and swapped
# the matching pattern into the hold space.
x
/meanies/q 0
# If we don't match the replacement pattern then return falsy.
q 1
# This loop is only taken on a positive match, effectively
# just swapping the most recent match into the hold space.
:loop
x
sed -nf substitutions.sed data.txt && echo -e '\nGood' || echo -e '\nBad'
sed -nf substitutions.sed data.txt && echo -e '\nGood' || echo -e '\nBad'