egrep -v ‘^#‘ :-v,取反匹配

 cat   /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local



[root@node-201 softwares]# egrep -v '^#'   /etc/rc.local

touch /var/lock/subsys/local



[root@node-201 softwares]# egrep '^#'   /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
常用命令选项

-E,grep 支持扩展正则 egrep不需要
-v,取反匹配
-i,忽略大小写
-c,统计匹配行数
-q,静默输出,无任何输出,一般用于检测
-n,显示出匹配结果所在的行号
--color,标红显示匹配字串
-w 完全匹配
-m 匹配指定前n行
•grep 正则表达式,用来查找过滤文档的工具符号
grep "root" user //在user文档中查找有单词root的行
grep "^root" user //在user文档中查找以单词root开头的行
grep "bash$" user //在user文档中查找以单词bash结尾的行
grep "^$" user //查找空行
grep "^ " user //查找以空格开头的行
grep "[rot]" user //查找字母r或者o或者t
grep "roo[tn]" user //查找root或者roon
grep "1" user //查找字母r或者o或者t之外的内容
grep "[a-z]" user //查找小写字母
grep "[A-Z]" user //查找大写字母
grep "[a-Z]" user //查找所有字母
grep "[0-9]" user //查找数字

grep "r..t" user //查找以r开头t结尾中间有2个任意字符的单词
grep "r." user //查找以r开头后面任意字符 相当手通配符
grep "ro*" user //查找以r开头后面有或没有字母o的单词,o可以出现任意次
grep "o{1,2}" user //查找o出现1次到2次的行
grep "o{2,3}" user //查找o出现2次到3次的行
grep "o{2}" user //查找o出现2次的行
grep "o{1,} " user //查找o出现1次以及1次以上
grep "(:0){2}" user //查找:0(数字零)连续出现2次的行
扩展正则
egrep "o+" user //查找o出现1次以及1次以上
egrep "o?" user //查找o出现0次或1次
egrep "o{1,2}" user //查找o出现1次到2次的行
egrep "o{2,3}" user //查找o出现2次到3次的行
egrep "o{2}" user //查找o出现2次的行
egrep "o{1,}" user //查找o出现1次以及1次以上
egrep "(:0){2}" user //查找:0(数字零)连续出现2次的行
egrep "bash|nologin" user //查找bash或者nologin
egrep "\bthe\b" a //查找单词the,前后是空格或者特殊符号

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值