M20-1扩展正则表达式作业

1、取本机ip地址

[root@centos6 ~]# ifconfig
eth1      Link encap:Ethernet  HWaddr 00:0C:29:35:DD:AB
          inet addr:10.1.253.95  Bcast:10.1.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fe35:ddab/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:378023 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12444 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:46926222 (44.7 MiB)  TX bytes:1240063 (1.1 MiB)
eth2      Link encap:Ethernet  HWaddr 00:0C:29:35:DD:B5
          inet addr:192.168.226.135  Bcast:192.168.226.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe35:ddb5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2539 errors:0 dropped:0 overruns:0 frame:0
          TX packets:225 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:281133 (274.5 KiB)  TX bytes:39650 (38.7 KiB)
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
[root@centos6 ~]# ifconfig |awk -F '[: ]+' 'NR==2{print $4}'
10.1.253.95
[root@centos6 ~]# ifconfig
eth1      Link encap:Ethernet  HWaddr 00:0C:29:35:DD:AB
          inet addr:10.1.253.95  Bcast:10.1.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fe35:ddab/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:379965 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12615 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:47097014 (44.9 MiB)  TX bytes:1264173 (1.2 MiB)

eth2      Link encap:Ethernet  HWaddr 00:0C:29:35:DD:B5
          inet addr:192.168.226.135  Bcast:192.168.226.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe35:ddb5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2541 errors:0 dropped:0 overruns:0 frame:0
          TX packets:227 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:281535 (274.9 KiB)  TX bytes:40052 (39.1 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@centos6 ~]# ifconfig |head -2
eth1      Link encap:Ethernet  HWaddr 00:0C:29:35:DD:AB
          inet addr:10.1.253.95  Bcast:10.1.255.255  Mask:255.255.0.0
[root@centos6 ~]# ifconfig |head -2 |sed -r 's/^.*addr:(.*)  Bca.*$/\1/g'
eth1      Link encap:Ethernet  HWaddr 00:0C:29:35:DD:AB
10.1.253.95
[root@centos6 ~]# ifconfig |head -2|tail -1 |tr -s ' ' ':' |cut -d: -f4
10.1.253.95
[root@centos6 ~]#

1.1、取出本机所有的IP地址

[root@centos6 ~]# ifconfig |tr -cs '[:digit:].' '\n'|sort -t. -k4|tail -8
255.0.0.0
255.255.0.0
255.255.255.0
127.0.0.1
192.168.226.135
10.1.255.255
192.168.226.255
10.1.253.95
[root@centos6 ~]#

2、取各分区利用率的数值

[root@centos6 ~]# df |grep "sd.*"
/dev/sda3      121455724 3990720 111288700   4% /
/dev/sda1         194241   34082    149919  19% /boot
/dev/sdb        20511356   44992  19417788   1% /mnt
[root@centos6 ~]# df |grep "sd.*"|tr -s ' ' ':'
/dev/sda3:121455724:3990720:111288700:4%:/
/dev/sda1:194241:34082:149919:19%:/boot
/dev/sdb:20511356:44992:19417788:1%:/mnt
[root@centos6 ~]# df |grep "sd.*"|tr -s ' ' ':'|cut -d: -f1,5
/dev/sda3:4%
/dev/sda1:19%
/dev/sdb:1%
[root@centos6 ~]# df |grep "sd.*"|tr -s ' ' ':'|cut -d: -f1,5|sort -nr
/dev/sdb:1%
/dev/sda3:4%
/dev/sda1:19%
[root@centos6 ~]#

3、统计/etc/init.d/functions 文件中每个单词出现的次数,并按频率从高到低显示

[root@centos6 ~]# cat /etc/init.d/functions |tr -cs '[:alpha:]' '\n'|sort|uniq -c |sort-nr
     83 if
     77 then
     75 pid
     73 echo
     72 fi
     61 return
     57 dev
     54 file
     50 n
     46 local

4、/etc/rc.d/init.d/functions或/etc/rc.d/init.d/functions/"  取目录名

[root@centos6 ~]# echo "/etc/init.d/functions"|sed -r 's#^(/.*/)[^/]+/?#\1#g'
/etc/init.d/
[root@centos6 ~]#

4.1、/etc/rc.d/init.d/functions或/etc/rc.d/init.d/functions/"  取基名

[root@centos6 ~]# echo "/etc/init.d/functions/"|sed -r 's#/.*/([^/]+)#\1#g'
functions/
[root@centos6 ~]#

5、正则表达式表示身份证号

egrep "\<((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|(71|81|82))([0-9]){4}(19|20)([0-9]){2}((0[1-9])|(1[0-2]))(0[1-9]|([0-9])|(2[0-9])|(3[0-1]))([0-9]){3}([0-9]|X)\>" filename

6、正则表达式表示手机号

grep -E -o "(\+86)?1[38][0-9]{9}|14[57][0-9]{8}|15[0-35-9][0-9]{8}|17[0678][0-9]{8}" phonenumber

7、正则表达式表示邮箱

egrep "\<([[:alnum:]]+(-|_)*[[:alnum:]]*)\>@([[:alnum:]]+\.)+[[:alnum:]]+" mail 
grep -E -o '[a-zA-Z0-9]+[[:alnum:]\.\_-]*@[a-zA-Z0-9]+[[:alnum:]\.\_-]*' phonenumber

8、正则表达式表示QQ号

grep -E -o '\b[1-9][0-9]{4,12}\b' phonenumber

原创文章,作者:alren,如若转载,请注明出处:http://www.178linux.com/31460

(0)
alrenalren
上一篇 2016-08-10 10:15
下一篇 2016-08-10

相关推荐

  • 第十周

    1、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情) 1.开启电源后,POST自检:检查硬件设备,通过后交给BIOS 2.BIOS加载可选择的启动设备,寻找可引导的启动设备的记录:MBR 3.MBR:硬盘的主引导记录,存在于0磁道0扇区,共512字节.其中Bootloader占用446字节,分区表占用64字节,magic nu…

    Linux干货 2016-10-17
  • Windows 10 VS. Linux

    原文出处: Linux中国 – zpl1025   前阵子 Windows 10 好像占据了绝大部分头条,甚至在一些Linux圈里也是一样。最具代表性的是 betanews.com 的 Brian Fagioli 说 Windows 10 已经为 Linux 桌面系统敲响了丧钟,Microsoft 如今宣布将为忠实的…

    系统运维 2015-03-24
  • SSH——安全的通信

    SSH ·ssh:secure shell, protocol, 22/tcp,  安全的远程登录 ·OpenSSH:ssh协议的开源实现 ·dropbear:另一个开源实现 ·SSH协议版本:          v1:基于CRC-32做MAC,不安全;man-in-m…

    Linux干货 2016-09-25
  • N26_第一周

    计算机组成     CPU:核心部件:                 运算器: 对数据进行算术运算和逻辑运算     …

    Linux干货 2017-01-11
  • 马哥教育网络班21期+第7周课程练习

    1、创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; [root@localhost ~]# fdisk /dev/sda WARNING: DOS-compatible mode is&n…

    Linux干货 2016-08-24
  • 自制简易linux系统

    一、环境准备 1.笔记本电脑 2.vmware12软件 3.CentOS 6虚拟机 4.大于5G空间的物理磁盘分区 二、分区并挂载文件系统 1.添加磁盘 在vmware中选中CentOS 6系统并右击鼠标选择设置,添加–>硬盘–>SCSI(推荐)–>创建新虚拟磁盘–>大小改为5G–>完成 2.分区并…

    Linux干货 2016-09-20