SED - 在一行中搜索两个模式,如果找到模式匹配,则在行尾插入几个单词 [英] SED - Search two pattern in a line and insert few word at the end of the line if pattern match is found

查看:37
本文介绍了SED - 在一行中搜索两个模式,如果找到模式匹配,则在行尾插入几个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,我想在同一行中搜索两个 pttern,如果找到,应在该行的末尾插入一个单词.想在 sed 中做.

I have a file and i want to search two pttern in the same line and if found one word should be inserted at the end of the line. want to do in a sed .

示例

我有一个像下面这样的文件内容,想搜索 unix 和 NotOK

I have a file contents like below , want to search unix and NotOK

abc unix windows DBa NotOK 
abc unix windows DBa OK
abc oracle sybase java OK

输出应该是这样的(匹配abc和NotOK,如果找到,在行尾插入unix)

output should be like (Match abc and NotOK and if found , insert unix at the end of the line)

abc unix windows DBa NotOK "unix"
abc unix windows DBa OK
abc oracle sybase java OK

推荐答案

[[bash_prompt$]]$ cat log
abc unix windows DBa NotOK
abc unix windows DBa OK
abc oracle sybase java OK
[[bash_prompt$]]$ sed -e 's/^.*unix.*NotOK.*$/& "unix"/g' log
abc unix windows DBa NotOK  "unix"
abc unix windows DBa OK
abc oracle sybase java OK

这篇关于SED - 在一行中搜索两个模式,如果找到模式匹配,则在行尾插入几个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆