九、Linux文本过滤

作者: 下午茶_da6d | 来源:发表于2019-11-15 15:29 被阅读0次

文本过滤grep:

语法格式:
grep [选项] 基本正则表达式 [文件]
常用的grep选项有:
-c 只输出匹配行的计数。

[avatar@xxx ~]$ grep -c "root" /etc/passwd 
2

-i 不区分大小写(只适用于单字符)。

[avatar@xxx ~]$ grep -i "Root" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

-n 显示匹配行及行号。

[avatar@xxx ~]$ grep -n "root" /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
11:operator:x:11:0:operator:/root:/sbin/nologin

-v 显示不包含匹配文本的所有行。
[avatar@xxx ~]$ ps aux | grep "java" |grep -v "grep"
参考文档:https://www.runoob.com/linux/linux-comm-grep.html

grep 工作中常常和管道符联合使用,比如查询进程是否正常运行

 ps aux | grep "rabbitmq" | grep -v "grep"

相关文章

  • 九、Linux文本过滤

    文本过滤grep: 语法格式:grep [选项] 基本正则表达式 [文件]常用的grep选项有:-c 只输...

  • Linux上文本处理三剑客grep及正则表达式

    Linux上文本处理三剑客: grep, egrep, fgrep:文本过滤工具,通过(模式:pattern)过滤...

  • 正则表达式

    用于过滤文本时的附加条件,用来更精确的过滤文本内容。 wget http://linux.vbird.org/li...

  • 关于grep命令的一个小坑

    在Linux文本中有三个文本处理工具分别是: grep:文本过滤(模式:pattern)工具 gre...

  • grep及正则表达式

    grep Linux上文本出来三剑客grep:文本过滤(模式:pattern)工具;grep ,egrep ,fg...

  • Grep

    Linux文本处理三剑客 grep:文本过滤(模式:pattern)工具grep, egrep, fgrep(不支...

  • linux日志文本过滤

    一般日志过滤处理: 查找关键日志grep 精简日志内容sed 对记录进行排序sort针对文本文件内容,以行为单位排...

  • grep 及正则表达式

    Linux 上文本处理三剑客 grep:文本过滤(模式:pattern)工具grep(基本匹配),egrep(扩展...

  • note_6.3_grep命令与基本正则表达式

    文本处理工具 Linux上文本处理三剑客:  grep,egrep, fgrep:文本过滤工具(模式:patter...

  • Linux下的文本过滤神器-grep

    1. grep简介 grep是Linux中用来过滤文本文件内容的命令,使用该命令能够高效的从文本信息中过滤出符合条...

网友评论

    本文标题:九、Linux文本过滤

    本文链接:https://www.haomeiwen.com/subject/tqnjictx.html