linux三剑客之grep

Matching Control

-i :Ignore case 忽略大小写
在这里插入图片描述

-w:whole words 按照整个单词匹配
在这里插入图片描述

-v:Invert the sense of matching, to select non-matching lines 匹配不包含指定关键字的行
在这里插入图片描述

Output Line Prefix Control

-n:line number 在行前显示行号
在这里插入图片描述

Context Line Control

-A NUM:Print NUM lines of trailing context after matching lines. 显示关键字所在行的后NUM行

-B NUM:Print NUM lines of leading context before matching lines. 显示关键字所在行的前NUM行

-C NUM:Print NUM lines of output context 显示关键字前后NUM行
在这里插入图片描述

General Output Control

-c :print a count of matching lines 打印匹配关键在所在行的个数
在这里插入图片描述
注 : 此 选 项 只 能 统 计 行 数 \color{#FF3030}{注:此选项只能统计行数}
如果想要统计关键字的个数,则需要使用
-o:only-matching 只显示匹配的关键字
在这里插入图片描述

Regular Expression

meta-characterexplain
.The period ‘.’ matches any single character.
?The preceding item is optional and will be matched at most once.
*The preceding item will be matched zero or more times.
+The preceding item will be matched one or more times.
{N}The preceding item is matched exactly N times.
{N,}The preceding item is matched N or more times.
{,M}The preceding item is matched at most M times. This is a GNU extension.
{N,M}The preceding item is matched at least N times, but not more than M times.
[]It matches any single character in that list; if the first character of the list is the caret ‘^’, then it matches any character not in the list.
^,$The caret ‘^’ and the dollar sign ‘$’ are meta-characters that respectively match the empty string at the beginning and end of a line.
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值