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)