Chinaunix首页 | 论坛 | 博客
  • 博客访问: 160036
  • 博文数量: 32
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 155
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-08 09:08
个人简介

胖子不是一口吃成滴!

文章分类

全部博文(32)

文章存档

2017年(1)

2016年(4)

2014年(1)

2013年(26)

分类: LINUX

2013-03-29 13:41:03

 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来
1、输出真实的(不包含注释#信息)配置项 
-v ,Invert  the  sense  of  matching, to select non-matching lines.显示不包含匹配文本的所有行
-E Interpret  PATTERN  as  an  extended  regular expression,使用扩展正则表达式
^,基本正则表达式,行首定位符
$,基本正则表达式,行尾定位符
^$,空行
|,扩展正则表达式,或

行首定位符

点击(此处)折叠或打开

  1. # 查看/etc/sysconfig/selinux全部内容
  2. [root@oracle /]# cat /etc/sysconfig/selinux
  3. # This file controls the state of SELinux on the system.
  4. # SELINUX= can take one of these three values:
  5. # enforcing - SELinux security policy is enforced.
  6. # permissive - SELinux prints warnings instead of enforcing.
  7. # disabled - No SELinux policy is loaded.
  8. SELINUX=disabled
  9. # SELINUXTYPE= can take one of these two values:
  10. # targeted - Targeted processes are protected,
  11. # mls - Multi Level Security protection.
  12. SELINUXTYPE=targeted
  13. # 查看不包含注释行的/etc/sysconfig/selinux
  14. [root@oracle /]# cat /etc/sysconfig/selinux | grep -v '^#'
  15. SELINUX=disabled
  16. SELINUXTYPE=targeted
  17.  # 查看不包含注释行和空行的/etc/sysconfig/selinux
    [root@oracle /]# cat /etc/sysconfig/selinux | grep -v '^#' | grep -v '^$'   --基本正则表达式
    [root@oracle /]# cat /etc/sysconfig/selinux | grep -vE '^#|^$' [root@oracle /]# cat /etc/sysconfig/selinux | grep -vE '^#|^$'  --扩展正则表达式
    SELINUX=disabled
    SELINUXTYPE=targeted

2、匹配IP、MAC地址1、匹配IP、MAC地址
-o Print only the matched (non-empty) parts of  a  matching line, with each such part on a separate output line,只输出匹配字符串
{m,n},扩展正则表达式,m到n次匹配

点击(此处)折叠或打开

  1. [root@oracle ~]# ifconfig eth0
  2. eth0 Link encap:Ethernet HWaddr 00:0C:29:50:CB:D9
  3. inet addr:192.168.17.202 Bcast:192.168.17.255 Mask:255.255.255.0
  4. inet6 addr: fe80::20c:29ff:fe50:cbd9/64 Scope:Link
  5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  6. RX packets:258 errors:0 dropped:0 overruns:0 frame:0
  7. TX packets:199 errors:0 dropped:0 overruns:0 carrier:0
  8. collisions:0 txqueuelen:1000
  9. RX bytes:24411 (23.8 KiB) TX bytes:24063 (23.4 KiB)
  10. Interrupt:19 Base address:0x2000
  11. [root@oracle ~]# ifconfig |grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'
  12. 192.168.17.202
  13. 192.168.17.255
  14. [root@oracle ~]# ifconfig eth0 | grep -oE '([0-9a-zA-Z]{1,2}:){5}[0-9a-zA-Z]{1,2}'
  15. 00:0C:29:50:CB:D9


阅读(1640) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~