sed is for simple substitutions on individual lines, s/old/new/
, that is all. For anything else you should be using awk as all those crazy sed constructs to do more than that became obsolete in the mid 1980s when awk was invented.
It's hard to say without concise, testable sample input and expected output but given this sample input (from https://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf):
$ cat file
# Default LLT value for this interface in milliseconds. The value used in case
# no value provided during session setup. Default is 50 msec.
# fst_llt is in 1..4294967 range (due to spec limitation, see 10.32.2.2
# Transitioning between states).
#fst_llt=100
# Example blocks:
# Simple case: WPA-PSK, PSK as an ASCII passphrase, allow all valid ciphers
network={
ssid="simple"
psk="very secret passphrase"
priority=5
}
# Same as previous, but request SSID-specific scanning (for APs that reject
# broadcast SSID)
network={
ssid="second ssid"
scan_ssid=1
psk="very secret passphrase"
priority=2
}
# Only WPA-PSK is used. Any valid cipher combination is accepted.
network={
ssid="example"
proto=WPA
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP WEP104 WEP40
psk=06b4be19da289f475aa46a33cb793029d4ab3db7a23ee92382eb0106c72ac7bb
priority=2
}
What you seem to be asking for would be as simple as this:
$ awk -v RS= -v ORS='\n\n' '/ssid="example"/' file
# Only WPA-PSK is used. Any valid cipher combination is accepted.
network={
ssid="example"
proto=WPA
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP WEP104 WEP40
psk=06b4be19da289f475aa46a33cb793029d4ab3db7a23ee92382eb0106c72ac7bb
priority=2
}
and the opposite would be to simply negate the test for /ssid="example"/
:
$ awk -v RS= -v ORS='\n\n' '!/ssid="example"/' file
# Default LLT value for this interface in milliseconds. The value used in case
# no value provided during session setup. Default is 50 msec.
# fst_llt is in 1..4294967 range (due to spec limitation, see 10.32.2.2
# Transitioning between states).
#fst_llt=100
# Example blocks:
# Simple case: WPA-PSK, PSK as an ASCII passphrase, allow all valid ciphers
network={
ssid="simple"
psk="very secret passphrase"
priority=5
}
# Same as previous, but request SSID-specific scanning (for APs that reject
# broadcast SSID)
network={
ssid="second ssid"
scan_ssid=1
psk="very secret passphrase"
priority=2
}
If that's not what you want then edit your question to provide sample input and expected output that clarifies your requirements and we can test against so we can provide a different but still clear and trivial awk solution.