linux - 如何使用通配符从 linux 中的一行中删除特定模式

标签 linux shell awk sed grep

如何使用通配符从 linux 中的一行中删除特定模式?

test07cel20: ((host=test07db04.com,port=1832,community=public,(host=test07db02.com,port=1832,community=public),(host=172.186.100.63,port=162,community=public,type=ASR))

我想从上面的行中删除 (host=172.186.100.63,port=162,community=public,type=ASR)172.186.100.63, public 将逐个改变(我的意思是变量),所以寻找一些通配符方法。

此外,该模式将始终存在于行尾。在某些情况下,type=ASR 将是 type=asr。因此,如果您有任何想法涵盖上述所有从一行中删除模式 host=*,port=162,community=*,type=ASR 的场景。非常感谢任何帮助。

预期输出是

(host=test07db04.com,port=1832,community=public),(host=test07db02.com,port=1832,community=public)

最佳答案

您的解决方案过于复杂。尝试这样的事情:

sed 's/,(host=[^(]*,port=162,[^(]*type=[Aa][Ss][Rr])//'

关于linux - 如何使用通配符从 linux 中的一行中删除特定模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41820574/

相关文章:

linux - 如何grep值小于或等于值的行

linux - 如何在退出 chroot 后立即运行 linux 命令

c - 通用 scsi ioctl 后 fread 期间出现段错误

linux - 如何在每次 grep 找到某些东西时增加变量的值

linux - AWK如何计算累计和并在超过预定义整数后停止?

linux - 使用 R/awk 打印文件中列的标准差

c - Ubuntu 中的 wait() 函数

linux - 在另一个文件中反射(reflect)一个文件的类型

linux - bash - 使用 int 变量作为引用传递给函数的位置参数的索引

linux - 仅当输出发生变化时才从控制台提取信息