我怎样才能用grep排除一个单词

我怎样才能用grep排除一个单词

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

问题描述

我需要这样的:

  grep ^unwanted_wordXXXXXXXX 


解决方案

您也可以使用 -v 选项grep as:

  grep -vunwanted_wordfile | grep XXXXXXXX 

grep -vunwanted_wordfile 将过滤具有 unwanted_word grep XXXXXXXX 的行将仅列出具有 XXXXXXXX



编辑:

注释它看起来像你想列出所有行,而不是 unwanted_word 。在这种情况下,所有你需要的是:

$ p $ grep -v'unwanted_word'文件


I need something like:

grep ^"unwanted_word"XXXXXXXX
解决方案

You can also do it using -v option of grep as:

grep -v "unwanted_word" file | grep 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.

EDIT:

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排除一个单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:38