我需要用另一个字符串替换模式匹配行。
例子
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
关于linux - 使用 sed/grep 更新匹配行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13530378/