Linux扩展正则表达式及sed生产环境用法

1、取本机ip地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[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地址

1
2
3
4
5
6
7
8
9
10
[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、取各分区利用率的数值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[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 文件中每个单词出现的次数,并按频率从高到低显示

1
2
3
4
5
6
7
8
9
10
11
[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/"  取目录名

1
2
3
[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/"  取基名


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



本文转自chengong1013 51CTO博客,原文链接:http://blog.51cto.com/purify/1835797,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值