grep 条件 文件
数据
echo 1 >test.log
echo 2 >>test.log
echo 3 >>test.log
echo 15>>test.log
搜索
cat test.log | grep 1 //利用管道符
结果
1
15
12
grep 1 test.log
结果
1
15
12
取反 参数-v
grep -v 1 test.log
结果
2
3
显示行号 参数-n
grep -n 1 test.log
结果
1:1
4:15
5:12
多少行含有某个值 参数-c
grep -c 1 test.log
3
多个匹配模式 参数-e
grep -e 1 -e 2 tese.log
结果
1
2
15
12
正则 []
grep ' [1*]' test.log //Mac 下可用
grep [1*] test.log //linux
结果
1
15
12
连贯使用
grep -nv '[1*]' test.log
结果
2:2
3:3