博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
grep、awk、sed的巩固练习
阅读量:5282 次
发布时间:2019-06-14

本文共 21136 字,大约阅读时间需要 70 分钟。

作者:邓聪聪

提取日志或文本中的关键内容

1 Apr 23 09:34:05 localhost NetworkManager[1399]: 
(eno16777736): Activation: starting connection 'eno16777736' (ecefc7de-e893-4eee-88fd-bb9843616ec2) 2 Apr 23 09:34:05 localhost NetworkManager[1399]:
(eno16777736): device state change: disconnected -> prepare (reason 'none') [30 40 0] 3 Apr 23 09:34:05 localhost NetworkManager[1399]:
NetworkManager state is now CONNECTING 4 Apr 23 09:34:05 localhost NetworkManager[1399]:
(eno16777736): device state change: prepare -> config (reason 'none') [40 50 0] 5 Apr 23 09:34:05 localhost NetworkManager[1399]:
(eno16777736): device state change: config -> ip-config (reason 'none') [50 70 0] 6 Apr 23 09:34:05 localhost NetworkManager[1399]:
Activation (eno16777736) Beginning DHCPv4 transaction (timeout in 45 seconds) 7 Apr 23 09:34:05 localhost NetworkManager[1399]:
dhclient started with pid 11327 8 Apr 23 09:34:05 localhost dhclient[11327]: DHCPDISCOVER on eno16777736 to 255.255.255.255 port 67 interval 7 (xid=0x398e2136) 9 Apr 23 09:34:06 localhost dhclient[11327]: DHCPREQUEST on eno16777736 to 255.255.255.255 port 67 (xid=0x398e2136) 10 Apr 23 09:34:06 localhost dhclient[11327]: DHCPOFFER from 10.0.0.254 11 Apr 23 09:34:06 localhost dhclient[11327]: DHCPACK from 10.0.0.254 (xid=0x398e2136) 12 Apr 23 09:34:06 localhost NetworkManager[1399]:
address 10.0.0.132 13 Apr 23 09:34:06 localhost NetworkManager[1399]:
plen 24 (255.255.255.0) 14 Apr 23 09:34:06 localhost NetworkManager[1399]:
gateway 10.0.0.2 15 Apr 23 09:34:06 localhost NetworkManager[1399]:
server identifier 10.0.0.254 16 Apr 23 09:34:06 localhost NetworkManager[1399]:
lease time 1800 17 Apr 23 09:34:06 localhost NetworkManager[1399]:
nameserver '10.0.0.2' 18 Apr 23 09:34:06 localhost NetworkManager[1399]:
domain name 'localdomain' 19 Apr 23 09:34:06 localhost NetworkManager[1399]:
(eno16777736): DHCPv4 state changed unknown -> bound 20 Apr 23 09:34:06 localhost NetworkManager[1399]:
(eno16777736): device state change: ip-config -> ip-check (reason 'none') [70 80 0] 21 Apr 23 09:34:06 localhost NetworkManager[1399]:
(eno16777736): device state change: ip-check -> secondaries (reason 'none') [80 90 0] 22 Apr 23 09:34:06 localhost NetworkManager[1399]:
(eno16777736): device state change: secondaries -> activated (reason 'none') [90 100 0] 23 Apr 23 09:34:06 localhost NetworkManager[1399]:
NetworkManager state is now CONNECTED_LOCAL 24 Apr 23 09:34:06 localhost NetworkManager[1399]:
NetworkManager state is now CONNECTED_GLOBAL 25 Apr 23 09:34:06 localhost NetworkManager[1399]:
Policy set 'eno16777736' (eno16777736) as default for IPv4 routing and DNS. 26 Apr 23 09:34:06 localhost NetworkManager[1399]:
(eno16777736): Activation: successful, device activated. 27 Apr 23 09:34:06 localhost nm-dispatcher: Dispatching action 'up' for eno16777736 28 Apr 23 09:34:06 localhost network: Bringing up interface eno16777736: Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1) 29 Apr 23 09:34:06 localhost dhclient[11327]: bound to 10.0.0.132 -- renewal in 735 seconds. 30 Apr 23 09:34:06 localhost network: [ OK ] 31 Apr 23 09:34:06 localhost systemd: Started LSB: Bring up/down networking. 32 Apr 23 09:35:47 localhost dbus[1172]: avc: received setenforce notice (enforcing=0) 33 Apr 23 09:35:47 localhost dbus-daemon: dbus[1172]: avc: received setenforce notice (enforcing=0) 34 Apr 23 09:37:16 localhost systemd: Stopping firewalld - dynamic firewall daemon... 35 Apr 23 09:37:16 localhost kernel: Ebtables v2.0 unregistered 36 Apr 23 09:37:16 localhost systemd: Stopped firewalld - dynamic firewall daemon. 37 Apr 23 09:37:56 localhost systemd: Started Session 2 of user root. 38 Apr 23 09:37:56 localhost systemd-logind: New session 2 of user root. 39 Apr 23 09:37:56 localhost systemd: Starting Session 2 of user root. 40 Apr 23 09:46:21 localhost dhclient[11327]: DHCPREQUEST on eno16777736 to 10.0.0.254 port 67 (xid=0x398e2136) 41 Apr 23 09:46:21 localhost dhclient[11327]: DHCPACK from 10.0.0.254 (xid=0x398e2136) 42 Apr 23 09:46:21 localhost NetworkManager[1399]:
address 10.0.0.132 43 Apr 23 09:46:21 localhost NetworkManager[1399]:
plen 24 (255.255.255.0) 44 Apr 23 09:46:21 localhost NetworkManager[1399]:
gateway 10.0.0.2 45 Apr 23 09:46:21 localhost NetworkManager[1399]:
server identifier 10.0.0.254 46 Apr 23 09:46:21 localhost NetworkManager[1399]:
lease time 1800 47 Apr 23 09:46:21 localhost NetworkManager[1399]:
nameserver '10.0.0.2' 48 Apr 23 09:46:21 localhost NetworkManager[1399]:
domain name 'localdomain' 49 Apr 23 09:46:21 localhost NetworkManager[1399]:
(eno16777736): DHCPv4 state changed bound -> bound 50 Apr 23 09:46:21 localhost dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' 51 Apr 23 09:46:21 localhost systemd: Starting Network Manager Script Dispatcher Service... 52 Apr 23 09:46:21 localhost dbus-daemon: dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' 53 Apr 23 09:46:21 localhost dhclient[11327]: bound to 10.0.0.132 -- renewal in 823 seconds. 54 Apr 23 09:46:21 localhost dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher' 55 Apr 23 09:46:21 localhost dbus-daemon: dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher' 56 Apr 23 09:46:21 localhost systemd: Started Network Manager Script Dispatcher Service. 57 Apr 23 09:46:21 localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736 58 Apr 23 09:46:57 localhost systemd: Starting Cleanup of Temporary Directories... 59 Apr 23 09:46:57 localhost systemd: Started Cleanup of Temporary Directories. 60 Apr 23 10:00:04 localhost dhclient[11327]: DHCPREQUEST on eno16777736 to 10.0.0.254 port 67 (xid=0x398e2136) 61 Apr 23 10:00:04 localhost dhclient[11327]: DHCPACK from 10.0.0.254 (xid=0x398e2136) 62 Apr 23 10:00:04 localhost NetworkManager[1399]:
address 10.0.0.132 63 Apr 23 10:00:04 localhost NetworkManager[1399]:
plen 24 (255.255.255.0) 64 Apr 23 10:00:04 localhost NetworkManager[1399]:
gateway 10.0.0.2 65 Apr 23 10:00:04 localhost NetworkManager[1399]:
server identifier 10.0.0.254 66 Apr 23 10:00:04 localhost NetworkManager[1399]:
lease time 1800 67 Apr 23 10:00:04 localhost NetworkManager[1399]:
nameserver '10.0.0.2' 68 Apr 23 10:00:04 localhost NetworkManager[1399]:
domain name 'localdomain' 69 Apr 23 10:00:04 localhost NetworkManager[1399]:
(eno16777736): DHCPv4 state changed bound -> bound 70 Apr 23 10:00:04 localhost dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' 71 Apr 23 10:00:04 localhost dbus-daemon: dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' 72 Apr 23 10:00:04 localhost systemd: Starting Network Manager Script Dispatcher Service... 73 Apr 23 10:00:04 localhost dhclient[11327]: bound to 10.0.0.132 -- renewal in 707 seconds. 74 Apr 23 10:00:04 localhost dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher' 75 Apr 23 10:00:04 localhost dbus-daemon: dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher' 76 Apr 23 10:00:04 localhost systemd: Started Network Manager Script Dispatcher Service. 77 Apr 23 10:00:04 localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736 78 Apr 23 10:01:01 localhost systemd: Started Session 3 of user root. 79 Apr 23 10:01:01 localhost systemd: Starting Session 3 of user root. 80 Apr 23 10:11:51 localhost dhclient[11327]: DHCPREQUEST on eno16777736 to 10.0.0.254 port 67 (xid=0x398e2136) 81 Apr 23 10:11:51 localhost dhclient[11327]: DHCPACK from 10.0.0.254 (xid=0x398e2136) 82 Apr 23 10:11:51 localhost NetworkManager[1399]:
address 10.0.0.132 83 Apr 23 10:11:51 localhost NetworkManager[1399]:
plen 24 (255.255.255.0) 84 Apr 23 10:11:51 localhost NetworkManager[1399]:
gateway 10.0.0.2 85 Apr 23 10:11:51 localhost NetworkManager[1399]:
server identifier 10.0.0.254 86 Apr 23 10:11:51 localhost NetworkManager[1399]:
lease time 1800 87 Apr 23 10:11:51 localhost NetworkManager[1399]:
nameserver '10.0.0.2' 88 Apr 23 10:11:51 localhost NetworkManager[1399]:
domain name 'localdomain' 89 Apr 23 10:11:51 localhost NetworkManager[1399]:
(eno16777736): DHCPv4 state changed bound -> bound 90 Apr 23 10:11:51 localhost dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' 91 Apr 23 10:11:51 localhost systemd: Starting Network Manager Script Dispatcher Service... 92 Apr 23 10:11:51 localhost dbus-daemon: dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' 93 Apr 23 10:11:51 localhost dhclient[11327]: bound to 10.0.0.132 -- renewal in 781 seconds. 94 Apr 23 10:11:51 localhost dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher' 95 Apr 23 10:11:51 localhost dbus-daemon: dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher' 96 Apr 23 10:11:51 localhost systemd: Started Network Manager Script Dispatcher Service. 97 Apr 23 10:11:51 localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736 98 Apr 23 10:24:52 localhost dhclient[11327]: DHCPREQUEST on eno16777736 to 10.0.0.254 port 67 (xid=0x398e2136) 99 Apr 23 10:24:52 localhost dhclient[11327]: DHCPACK from 10.0.0.254 (xid=0x398e2136)100 Apr 23 10:24:52 localhost NetworkManager[1399]:
address 10.0.0.132101 Apr 23 10:24:52 localhost NetworkManager[1399]:
plen 24 (255.255.255.0)102 Apr 23 10:24:52 localhost NetworkManager[1399]:
gateway 10.0.0.2103 Apr 23 10:24:52 localhost NetworkManager[1399]:
server identifier 10.0.0.254104 Apr 23 10:24:52 localhost NetworkManager[1399]:
lease time 1800105 Apr 23 10:24:52 localhost NetworkManager[1399]:
nameserver '10.0.0.2'106 Apr 23 10:24:52 localhost NetworkManager[1399]:
domain name 'localdomain'107 Apr 23 10:24:52 localhost NetworkManager[1399]:
(eno16777736): DHCPv4 state changed bound -> bound108 Apr 23 10:24:52 localhost dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'109 Apr 23 10:24:52 localhost systemd: Starting Network Manager Script Dispatcher Service...110 Apr 23 10:24:52 localhost dbus-daemon: dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'111 Apr 23 10:24:52 localhost dhclient[11327]: bound to 10.0.0.132 -- renewal in 885 seconds.112 Apr 23 10:24:52 localhost dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'113 Apr 23 10:24:52 localhost dbus-daemon: dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'114 Apr 23 10:24:52 localhost systemd: Started Network Manager Script Dispatcher Service.115 Apr 23 10:24:52 localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736116 Apr 23 10:39:38 localhost dhclient[11327]: DHCPREQUEST on eno16777736 to 10.0.0.254 port 67 (xid=0x398e2136)117 Apr 23 10:39:38 localhost dhclient[11327]: DHCPACK from 10.0.0.254 (xid=0x398e2136)118 Apr 23 10:39:38 localhost NetworkManager[1399]:
address 10.0.0.132119 Apr 23 10:39:38 localhost NetworkManager[1399]:
plen 24 (255.255.255.0)120 Apr 23 10:39:38 localhost NetworkManager[1399]:
gateway 10.0.0.2121 Apr 23 10:39:38 localhost NetworkManager[1399]:
server identifier 10.0.0.254122 Apr 23 10:39:38 localhost NetworkManager[1399]:
lease time 1800123 Apr 23 10:39:38 localhost NetworkManager[1399]:
nameserver '10.0.0.2'124 Apr 23 10:39:38 localhost NetworkManager[1399]:
domain name 'localdomain'125 Apr 23 10:39:38 localhost NetworkManager[1399]:
(eno16777736): DHCPv4 state changed bound -> bound126 Apr 23 10:39:38 localhost dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'127 Apr 23 10:39:38 localhost systemd: Starting Network Manager Script Dispatcher Service...128 Apr 23 10:39:38 localhost dbus-daemon: dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'129 Apr 23 10:39:38 localhost dhclient[11327]: bound to 10.0.0.132 -- renewal in 830 seconds.130 Apr 23 10:39:38 localhost dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'131 Apr 23 10:39:38 localhost dbus-daemon: dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'132 Apr 23 10:39:38 localhost systemd: Started Network Manager Script Dispatcher Service.133 Apr 23 10:39:38 localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736134 Apr 23 10:53:28 localhost dhclient[11327]: DHCPREQUEST on eno16777736 to 10.0.0.254 port 67 (xid=0x398e2136)135 Apr 23 10:53:28 localhost dhclient[11327]: DHCPACK from 10.0.0.254 (xid=0x398e2136)136 Apr 23 10:53:28 localhost NetworkManager[1399]:
address 10.0.0.132137 Apr 23 10:53:28 localhost NetworkManager[1399]:
plen 24 (255.255.255.0)138 Apr 23 10:53:28 localhost NetworkManager[1399]:
gateway 10.0.0.2139 Apr 23 10:53:28 localhost NetworkManager[1399]:
server identifier 10.0.0.254140 Apr 23 10:53:28 localhost NetworkManager[1399]:
lease time 1800141 Apr 23 10:53:28 localhost NetworkManager[1399]:
nameserver '10.0.0.2'142 Apr 23 10:53:28 localhost NetworkManager[1399]:
domain name 'localdomain'143 Apr 23 10:53:28 localhost NetworkManager[1399]:
(eno16777736): DHCPv4 state changed bound -> bound144 Apr 23 10:53:28 localhost dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'145 Apr 23 10:53:28 localhost dbus-daemon: dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'146 Apr 23 10:53:28 localhost systemd: Starting Network Manager Script Dispatcher Service...147 Apr 23 10:53:28 localhost dhclient[11327]: bound to 10.0.0.132 -- renewal in 747 seconds.148 Apr 23 10:53:28 localhost dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'149 Apr 23 10:53:28 localhost dbus-daemon: dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'150 Apr 23 10:53:28 localhost systemd: Started Network Manager Script Dispatcher Service.151 Apr 23 10:53:28 localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736152 Apr 23 11:01:01 localhost systemd: Started Session 4 of user root.153 Apr 23 11:01:01 localhost systemd: Starting Session 4 of user root.154 Apr 23 11:05:55 localhost dhclient[11327]: DHCPREQUEST on eno16777736 to 10.0.0.254 port 67 (xid=0x398e2136)155 Apr 23 11:05:55 localhost dhclient[11327]: DHCPACK from 10.0.0.254 (xid=0x398e2136)156 Apr 23 11:05:55 localhost NetworkManager[1399]:
address 10.0.0.132157 Apr 23 11:05:55 localhost NetworkManager[1399]:
plen 24 (255.255.255.0)158 Apr 23 11:05:55 localhost NetworkManager[1399]:
gateway 10.0.0.2159 Apr 23 11:05:55 localhost NetworkManager[1399]:
server identifier 10.0.0.254160 Apr 23 11:05:55 localhost NetworkManager[1399]:
lease time 1800161 Apr 23 11:05:55 localhost NetworkManager[1399]:
nameserver '10.0.0.2'162 Apr 23 11:05:55 localhost NetworkManager[1399]:
domain name 'localdomain'163 Apr 23 11:05:55 localhost NetworkManager[1399]:
(eno16777736): DHCPv4 state changed bound -> bound164 Apr 23 11:05:55 localhost dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'165 Apr 23 11:05:55 localhost systemd: Starting Network Manager Script Dispatcher Service...166 Apr 23 11:05:55 localhost dbus-daemon: dbus[1172]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'167 Apr 23 11:05:55 localhost dhclient[11327]: bound to 10.0.0.132 -- renewal in 869 seconds.168 Apr 23 11:05:55 localhost dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'169 Apr 23 11:05:55 localhost dbus-daemon: dbus[1172]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'170 Apr 23 11:05:55 localhost systemd: Started Network Manager Script Dispatcher Service.171 Apr 23 11:05:55 localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736
View Code

grep  dbus 3.log |sed -r 's/^.*host (.*): .*$/\1/g'|sed 's/dbus-daemon: //g'|awk  '{print $1}'

过滤关键字                搜索   

[root@admin ~]# ss -natState       Recv-Q Send-Q                                                   Local Address:Port                                                     Peer Address:Port LISTEN      0      128                                                                 :::10050                                                              :::*     LISTEN      0      128                                                                  *:10050                                                               *:*     LISTEN      0      25                                                                  :::514                                                                :::*     LISTEN      0      25                                                                   *:514                                                                 *:*     LISTEN      0      128                                                          127.0.0.1:199                                                                 *:*     LISTEN      0      50                                                                   *:3306                                                                *:*     LISTEN      0      20                                                                   *:587                                                                 *:*     LISTEN      0      20                                                                  :::587                                                                :::*     LISTEN      0      128                                                                 :::80                                                                 :::*     LISTEN      0      20                                                                   *:465                                                                 *:*     LISTEN      0      20                                                                  :::465                                                                :::*     LISTEN      0      128                                                                 :::22                                                                 :::*     LISTEN      0      128                                                                  *:22                                                                  *:*     LISTEN      0      20                                                                   *:25                                                                  *:*     LISTEN      0      20                                                                  :::25                                                                 :::*     ESTAB       0      52                                                        118.188.20.3:22                                                    221.122.103.135:62086 TIME-WAIT   0      0                                                          172.16.16.2:10050                                                     172.16.16.9:55678 TIME-WAIT   0      0                                                          172.16.16.2:10050                                                     172.16.16.9:55900 TIME-WAIT   0      0                                                          172.16.16.2:10050                                                     172.16.16.9:55904 TIME-WAIT   0      0                                                          172.16.16.2:10050                                                     172.16.16.9:55844 TIME-WAIT   0      0                                                          172.16.16.2:10050                                                     172.16.16.9:55872 TIME-WAIT   0      0                                                          172.16.16.2:10050                                                     172.16.16.9:55684 TIME-WAIT   0      0                                                          172.16.16.2:10050                                                     172.16.16.9:55700
View Code

用sed取第一列:

ss -ant|sed 's/[ \t].*//'

取出第一行的指定字符串,后项引用  磁盘使用率

df |sed -nr '/^\/dev/s/([^ ]+).*$/\1/p'

df |sed -nr '/^\/dev/s/.* (.*)%.*/\1/p'

转载于:https://www.cnblogs.com/dengcongcong/p/10763228.html

你可能感兴趣的文章
JS DOM对象
查看>>
python正则表达式
查看>>
OGR – Merging Multiple SHP files
查看>>
创业公司该不该被收购?(转)
查看>>
sqlserver 行转列、列转行[转]
查看>>
【IScroll深入学习】解决IScroll疑难杂症
查看>>
python 数据类型
查看>>
108-PHP类成员protected和private成员属性不能被查看数值
查看>>
ajax post data 获取不到数据,注意contentType
查看>>
css控制height充满浏览器视口
查看>>
Linux 系统目录结构
查看>>
查看CPU数量和核心数
查看>>
Android异步加载网络图片
查看>>
python学习之 - XML
查看>>
css问题小计
查看>>
Laravel学习笔记(三)数据库 数据库迁移
查看>>
ORACLE查看并修改最大连接数
查看>>
box-flex不均分问题
查看>>
Python--GIL 详解
查看>>
Oracle数据导入Mysql中
查看>>