如何用grep排除一个词? [英] How can I exclude one word with grep?

查看:21
本文介绍了如何用grep排除一个词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要类似的东西:

grep ^"unwanted_word"XXXXXXXX

推荐答案

您可以使用 grep 的 -v (for --invert-match) 选项作为:

You can do it using -v (for --invert-match) option of grep as:

grep -v "unwanted_word" file | grep XXXXXXXX

grep -v "unwanted_word" file 将过滤具有 unwanted_word 的行,grep XXXXXXXX 将仅列出具有模式 XXXXXXXX.

grep -v "unwanted_word" file will filter the lines that have the unwanted_word and grep XXXXXXXX will list only lines with pattern XXXXXXXX.

从您的评论看来,您想列出所有没有 unwanted_word 的行.在这种情况下,您只需要:

From your comment it looks like you want to list all lines without the unwanted_word. In that case all you need is:

grep -v 'unwanted_word' file

这篇关于如何用grep排除一个词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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