随笔19-Linux探索(三剑客之grep)

1. grep 命令简介

grep 命令是三剑客之一, grep 过滤查找, 可以单独用,也可以配合管道符来使用


2. 基本语法

grep [选项] 查找内容 源文件

3. 使用示例

grep -A n # 列出符合条件的行,并列出后续 的n行
grep -B n # 列出符合条件的行,并列出前面的n行
grep -c # 统计找到的符合条件的字符串的次数
grep -i # 忽略大小写
grep -n # 输出行号
grep -v # 反向查找
grep --color=auto # 标出颜色

(1)初始化一个测试文本

[root@localhost file]# touch grep.txt
[root@localhost file]# echo "This is the first line">>grep.txt
[root@localhost file]# echo "This is the second line">>grep.txt     
[root@localhost file]# echo "This is the third line">>grep.txt

(2)显示感兴趣的的内容

[root@localhost file]# grep first grep.txt
This is the first line
[root@localhost file]# 
[root@localhost file]#

(3)不显示不感兴趣的内容

[root@localhost file]# grep -v second grep.txt
This is the first line
This is the third line
[root@localhost file]#

4. egrep 命令

egrep 命令等同于(grep -E)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值