linux grep 排除_如何在Linux中排除Grep?

linux grep 排除

linux grep 排除

grep is very useful tool used by a lot of tech guys. grep provides different functions to match given text. We have all ready mentioned these useful options of grep. In this tutorial we will look different ways to exclude in grep.

grep是许多技术人员使用的非常有用的工具。 grep提供了不同的功能来匹配给定的文本。 我们已经准备好提及grep的这些有用选项。 在本教程中,我们将寻找在grep中排除的不同方法。

Linux egrep Command Tutorial with Examples

带有示例Linux egrep命令教程

-v选项排除(Exclude with -v  Option)

The basic way to exclude given term line from given text is -v  option. This will look for given term and remove line which contains term. In this example we will remove lines contains IP address 192.168.1.1 by using -v option.

从给定文本中排除给定术语行的基本方法是-v选项。 这将查找给定的术语并删除包含术语的行。 在此示例中,我们将使用-v选项删除包含IP地址192.168.1.1的行。

$ grep -v "192.168.115.128" syslog.1
How To Exclude with Grep In Linux?
How To Exclude with Grep In Linux?
如何在Linux中排除Grep?

多个Grep的多重排除 (Multiple Exclude with Multiple Grep)

What if we need multiple excludes? We can use multiple grep too. We can pipe multiple grep end to end. We will exclude poftut  and com terms from file named syslog.1 with the following command.

如果我们需要多个排除对象怎么办? 我们也可以使用多个grep 。 我们可以通过管道将多个grep端到端。 我们将使用以下命令从名为syslog.1文件中排除poftutcom术语。

$ grep -v "poftut" syslog.1 | grep "com"

扩展正则表达式的多重排除 (Multiple Exclude with Extended Regex)

grep  command provides extended regex functionality. This is used to provide multiple regex pattern in a single shot. We can use this feature in order to exclude multiple terms. We will use -e  option and provide regex patterns. We will exclude dhclient  and com with the following command.

grep命令提供了扩展的正则表达式功能。 这用于在单个镜头中提供多个正则表达式模式。 我们可以使用此功能来排除多个术语。 我们将使用-e选项并提供正则表达式模式。 我们将使用以下命令排除dhclientcom

$ grep -v  -e "dhclient" -e "com" syslog.1
Multiple Exclude with Extended Regex
Multiple Exclude with Extended Regex
扩展正则表达式的多重排除

排除尾部命令输出(Exclude Tail Command Output)

tail command provides the ability to read log files by streaming. But if there is a lot of logs this may be hard to read. We can use grep  with tail  command to gather to filter unwanted lines. We will pipe the tail  command output to the grep  command. We will filter lines those provides anacron

tail命令提供了通过流读取日志文件的功能。 但是,如果有很多日志,可能很难阅读。 我们可以将greptail命令一起使用,以过滤掉不需要的行。 我们将通过tail命令输出到grep命令。 我们将过滤那些提供anacron线

$ tail -f syslog.1 | grep -v "anacron"
Exclude with Tail Command
Exclude with Command Output
用命令输出排除
LEARN MORE  How To Use Regex (Regular Expression) with Grep?
了解更多如何在Grep中使用正则表达式(正则表达式)?

翻译自: https://www.poftut.com/exclude-grep-linux/

linux grep 排除

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值