目录
一、grep 文本过滤器
1.作用
Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户
2.grep 格式
grep 匹配条件 处理文件,grep -E = egrep
主要参数 | 描述 |
---|---|
grep root passwd | 过滤root关键字 |
grep -i root passwd | 忽略大小写,过滤root关键字 |
grep -E " \<root" passwd | root字符之前不能有字符 |
grep -E “root\>” passwd | root字符之后不能有字符 |
grep -数字 | 显示过滤行以及上面几行和下面几行 |
grep -n | 显示匹配的行所在行号 |
grep -A | 显示过滤行以及下面几行 |
grep -B | 显示过滤行以及上面几行 |
grep -v | 反向过滤 |
grep bash$ passwd 过滤bash结尾的行
grep -E “bash$ | nologin$” pasword 过滤bash结尾或nologin结尾的行
egrep “bash$ | nologin$” pasword 过滤bash结尾或nologin结尾的行
grep root pasword #过滤root行
grep -i root pasword #忽略大小写,过滤root行
grep -iE “\<root” pasword #忽略大小写,过滤root开头的行
grep -i “\<root\>” pasword #忽略大小写,过滤关键字只含有root的行
grep -n Root #显示Root行所在行号