[英]Updating matching line with sed/grep
我需要用另一個字符串替換模式匹配行。
例
line1
line2
the serial port is ttyS0
line4
我需要將包含ttyS0
行替換為
line1
line2
You have to use usb interface
line4
我該如何在sed(或grep)中做到這一點
我試過sed 's/ttyS0/You have to use usb interface/' myfile
。 但是它僅替換行中匹配的單詞。 我要替換整行。
像這樣:
sed 's/.*ttyS0.*/You have to use usb interface/' myfile
一種使用更改選項的方法:
sed '/ttyS0/c\You have to use usb interface' myfile
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.