linux - 使用 sed/grep 更新匹配行

标签 linux 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

关于linux - 使用 sed/grep 更新匹配行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13530378/

相关文章:

linux - Beaglebone 中的中断

linux - Bash 检查文件是否存在,然后检查文件中的子字符串

sed - sed 或 awk 可以使用 NUL 字符作为记录分隔符吗?

linux - Bash,Linux,需要根据另一个文件中的匹配内容从一个文件中删除行

git - 如何查找多于一行的 git 日志消息?

regex - ACK:从搜索中排除特定路径(目录及其子目录)

sql-server - 排序命令忽略第一行

c - 如果你懂 C 为什么还要学 bash?

linux - 在 linux 中过滤文本输出

c - 当服务器断开连接而不是进入无限循环时,如何让程序退出?