In general form, if you have a file with contents of form abcde, where section a precedes pattern b, then section c precedes pattern d, then section e follows, and you apply the following sed
commands, you get the following results.
In this demonstration, the output is represented by => abcde
, where the letters show which sections would be in the output. Thus, ae
shows an output of only sections a and e, ace
would be sections a, c, and e, etc.
Note that if b
or d
appear in the output, those are the patterns appearing (i.e., they're treated as if they're sections in the output).
Also don't confuse the /d/
pattern with the command d
. The command is always at the end in these demonstrations. The pattern is always between the //
.
sed -n -e '/b/,/d/!p' abcde
=> ae
sed -n -e '/b/,/d/p' abcde
=> bcd
sed -n -e '/b/,/d/{//!p}' abcde
=> c
sed -n -e '/b/,/d/{//p}' abcde
=> bd
sed -e '/b/,/d/!d' abcde
=> bcd
sed -e '/b/,/d/d' abcde
=> ae
sed -e '/b/,/d/{//!d}' abcde
=> abde
sed -e '/b/,/d/{//d}' abcde
=> ace