sed 删除不包含特定字符串的行 [英] sed delete lines not containing specific string

查看:66
本文介绍了sed 删除不包含特定字符串的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 sed 的新手,我有以下问题.在这个例子中:

I'm new to sed and I have the following question. In this example:

some text here
blah blah 123
another new line
some other text as well
another line

我想删除除包含字符串 'text' and 或字符串 'blah' 之外的所有行,因此我的输出文件如下所示:

I want to delete all lines except those that contain either string 'text' and or string 'blah', so my output file looks like this:

some text here
blah blah 123
some other text as well

任何提示如何使用 sed 完成此操作?

Any hints how this can be done using sed?

推荐答案

这可能对你有用:

sed '/text\|blah/!d' file
some text here
blah blah 123
some other text as well

这篇关于sed 删除不包含特定字符串的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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