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 10:22

相关推荐

  • 初窥门径之脚本书写

    一、几个脚本的编写: 1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 #!/bin/bash echo "HOSTNAME: $HOSTNAME" echo "IPV4 A…

    Linux干货 2016-08-15
  • linux基础之lvm操作流程

    linux基础之lvm基本操作流程    LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,它由Heinz Mauelshagen在Linux 2.4内核上实现,目前最新版本为:稳定版1.0.5,开发版 1.1.0-rc2,以及LVM2开发版。Linux用户安装L…

    2017-03-19
  • 关于Linux文件系统的的简单理解和认识-20160730

    关于Linux文件系统的的简单理解和认识 关于文件系统的运作,这与操作系统带的档案数据有关。例如Linux操作系统的档案权限(rwx)与文件属性(拥有者,群组,时间参数等)。文件系统通常会将这两部分的数据分别存放在不同的区块,权限与属性放置到inode中,至于实际数据则放置到date block区块中,另外,还有一个超级块区(super block)会记录整…

    Linux干货 2016-08-04
  • 磁盘管理

     磁盘管理  1 磁盘的结构  设备文件     I/O Ports: I/O设备地址  一切皆文件: open(), read(), write(), close()  设备类型: 块设备:block,存取单位“块”,磁盘 字符设备:char,存取单位“字符”,键盘  设备文件:关联至一个设备驱动程序…

    Linux干货 2016-08-26
  • 第四周作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。  cp -rf /etc/skel/  /home/ mv /home/skel /home/tuser1 chmod  -R 700 /home/tuser1 或chmod -R  …

    Linux干货 2016-12-03
  • linux中rpm命令的妙用

    linux中rpm命令的妙用 CentOS系统上使用rpm命令管理程序包: 安装、卸载、升级、查询、校验、数据库维护 安装:         rpm {-i|–install} [install-options] PACKAGE_FILE…    …

    Linux干货 2016-08-24