1,直接搜索
grep '关键字' grep.txt
2,常用搜索
grep -i 'test' grep.txt 不区分大小写
grep -n 'test' grep.txt 显示行数
grep --color 'test' grep.txt 高亮显示
grep -c 'test' grep.txt 显示符合条件的数量
grep -o 'test' grep.txt 只显示关键字不显示其他
grep -B1 'test' grep.txt 显示关键词包含上一行
grep -A1 'test' grep.txt 显示关键词下一行
grep -C1 'test' grep.txt 同时满足A和B
grep -w 'test' grep.txt 精确匹配
grep -v 'test' grep.txt 反向查找,不包含关键字
grep -e 123 -e 'test' grep.txt 同时搜索俩关键字
grep -q 222 grep.txt echo $? 输出0表示匹配到了,输出1表示未匹配到
grep -e "^w+{6,8}" grep.txt