删除位于两个字符串之间的文本
我查看了ddcutil detect --verbose的输出,并把结果保存到一个变量中。输出将类似于下面这样:
Invalid display
I2C bus: /dev/i2c-9
...
This monitor does not support DDC/CI. (I2C slave address x37 is unresponsive.)
If the monitor's on screen display has a DDC/CI setting, check it is enabled.
Monitor Model Id: HPN-HP_N246v-13578
Feature definition file HPN-HP_N246v-13578.mccs not found.
Display 1
I2C bus: /dev/i2c-6
...
VCP version: 2.2
Controller mfg: Mstar
Firmware version: 1.0
Monitor uses invalid feature flag in DDC reply packet to indicate unsupported feature.
Current dynamic sleep adjustment multiplier: 0.00
Monitor Model Id: HPN-HP_N246v-13578
Feature definition file HPN-HP_N246v-13578.mccs not found.
Invalid display
I2C bus: /dev/i2c-9
...
This monitor does not support DDC/CI. (I2C slave address x37 is unresponsive.)
If the monitor's on screen display has a DDC/CI setting, check it is enabled.
Monitor Model Id: HPN-HP_N246v-13578
Feature definition file HPN-HP_N246v-13578.mccs not found.
Display 2
I2C bus: /dev/i2c-7
...
VCP version: 2.1
Controller mfg: Novatek
Firmware version: 0.65
Monitor uses invalid feature flag in DDC reply packet to indicate unsupported feature.
Current dynamic sleep adjustment multiplier: 2.00
Monitor Model Id: HPN-HP_24o-13179
Feature definition file HPN-HP_24o-13179.mccs not found.
Invalid display
I2C bus: /dev/i2c-9
...
This monitor does not support DDC/CI. (I2C slave address x37 is unresponsive.)
If the monitor's on screen display has a DDC/CI setting, check it is enabled.
Monitor Model Id: HPN-HP_N246v-13578
Feature definition file HPN-HP_N246v-13578.mccs not found.
我想删除位于 "Invalid display" 与下一个空行之间的字符串,如下所示:
Display 1
I2C bus: /dev/i2c-6
...
VCP version: 2.2
Controller mfg: Mstar
Firmware version: 1.0
Monitor uses invalid feature flag in DDC reply packet to indicate unsupported feature.
Current dynamic sleep adjustment multiplier: 0.00
Monitor Model Id: HPN-HP_N246v-13578
Feature definition file HPN-HP_N246v-13578.mccs not found.
Display 2
I2C bus: /dev/i2c-7
...
VCP version: 2.1
Controller mfg: Novatek
Firmware version: 0.65
Monitor uses invalid feature flag in DDC reply packet to indicate unsupported feature.
Current dynamic sleep adjustment multiplier: 2.00
Monitor Model Id: HPN-HP_24o-13179
Feature definition file HPN-HP_24o-13179.mccs not found.
我尝试了 sed,但没有成功。有人能指点一下方向吗?非常感谢!
解决方案
您可以使用 d 命令,其中起始使用与 Invalid display 匹配的范围地址,结束处以一个空行为止:
sed '/Invalid display/,/^$/d' <<<"$variable"
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。