grep、awk、sed的巩固练习
作者:邓聪聪
提取日志或文本中的关键内容
Apr :: localhost NetworkManager[]: <info> (eno16777736): Activation: starting connection 'eno16777736' (ecefc7de-e893-4eee-88fd-bb9843616ec2)
Apr :: localhost NetworkManager[]: <info> (eno16777736): device state change: disconnected -> prepare (reason 'none') [ ]
Apr :: localhost NetworkManager[]: <info> NetworkManager state is now CONNECTING
Apr :: localhost NetworkManager[]: <info> (eno16777736): device state change: prepare -> config (reason 'none') [ ]
Apr :: localhost NetworkManager[]: <info> (eno16777736): device state change: config -> ip-config (reason 'none') [ ]
Apr :: localhost NetworkManager[]: <info> Activation (eno16777736) Beginning DHCPv4 transaction (timeout in seconds)
Apr :: localhost NetworkManager[]: <info> dhclient started with pid
Apr :: localhost dhclient[]: DHCPDISCOVER on eno16777736 to 255.255.255.255 port interval (xid=0x398e2136)
Apr :: localhost dhclient[]: DHCPREQUEST on eno16777736 to 255.255.255.255 port (xid=0x398e2136)
Apr :: localhost dhclient[]: DHCPOFFER from 10.0.0.254
Apr :: localhost dhclient[]: DHCPACK from 10.0.0.254 (xid=0x398e2136)
Apr :: localhost NetworkManager[]: <info> address 10.0.0.132
Apr :: localhost NetworkManager[]: <info> plen (255.255.255.0)
Apr :: localhost NetworkManager[]: <info> gateway 10.0.0.2
Apr :: localhost NetworkManager[]: <info> server identifier 10.0.0.254
Apr :: localhost NetworkManager[]: <info> lease time
Apr :: localhost NetworkManager[]: <info> nameserver '10.0.0.2'
Apr :: localhost NetworkManager[]: <info> domain name 'localdomain'
Apr :: localhost NetworkManager[]: <info> (eno16777736): DHCPv4 state changed unknown -> bound
Apr :: localhost NetworkManager[]: <info> (eno16777736): device state change: ip-config -> ip-check (reason 'none') [ ]
Apr :: localhost NetworkManager[]: <info> (eno16777736): device state change: ip-check -> secondaries (reason 'none') [ ]
Apr :: localhost NetworkManager[]: <info> (eno16777736): device state change: secondaries -> activated (reason 'none') [ ]
Apr :: localhost NetworkManager[]: <info> NetworkManager state is now CONNECTED_LOCAL
Apr :: localhost NetworkManager[]: <info> NetworkManager state is now CONNECTED_GLOBAL
Apr :: localhost NetworkManager[]: <info> Policy set 'eno16777736' (eno16777736) as default for IPv4 routing and DNS.
Apr :: localhost NetworkManager[]: <info> (eno16777736): Activation: successful, device activated.
Apr :: localhost nm-dispatcher: Dispatching action 'up' for eno16777736
Apr :: localhost network: Bringing up interface eno16777736: Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/)
Apr :: localhost dhclient[]: bound to 10.0.0.132 -- renewal in seconds.
Apr :: localhost network: [ OK ]
Apr :: localhost systemd: Started LSB: Bring up/down networking.
Apr :: localhost dbus[]: avc: received setenforce notice (enforcing=)
Apr :: localhost dbus-daemon: dbus[]: avc: received setenforce notice (enforcing=)
Apr :: localhost systemd: Stopping firewalld - dynamic firewall daemon...
Apr :: localhost kernel: Ebtables v2. unregistered
Apr :: localhost systemd: Stopped firewalld - dynamic firewall daemon.
Apr :: localhost systemd: Started Session of user root.
Apr :: localhost systemd-logind: New session of user root.
Apr :: localhost systemd: Starting Session of user root.
Apr :: localhost dhclient[]: DHCPREQUEST on eno16777736 to 10.0.0.254 port (xid=0x398e2136)
Apr :: localhost dhclient[]: DHCPACK from 10.0.0.254 (xid=0x398e2136)
Apr :: localhost NetworkManager[]: <info> address 10.0.0.132
Apr :: localhost NetworkManager[]: <info> plen (255.255.255.0)
Apr :: localhost NetworkManager[]: <info> gateway 10.0.0.2
Apr :: localhost NetworkManager[]: <info> server identifier 10.0.0.254
Apr :: localhost NetworkManager[]: <info> lease time
Apr :: localhost NetworkManager[]: <info> nameserver '10.0.0.2'
Apr :: localhost NetworkManager[]: <info> domain name 'localdomain'
Apr :: localhost NetworkManager[]: <info> (eno16777736): DHCPv4 state changed bound -> bound
Apr :: localhost dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost systemd: Starting Network Manager Script Dispatcher Service...
Apr :: localhost dbus-daemon: dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost dhclient[]: bound to 10.0.0.132 -- renewal in seconds.
Apr :: localhost dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost dbus-daemon: dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost systemd: Started Network Manager Script Dispatcher Service.
Apr :: localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736
Apr :: localhost systemd: Starting Cleanup of Temporary Directories...
Apr :: localhost systemd: Started Cleanup of Temporary Directories.
Apr :: localhost dhclient[]: DHCPREQUEST on eno16777736 to 10.0.0.254 port (xid=0x398e2136)
Apr :: localhost dhclient[]: DHCPACK from 10.0.0.254 (xid=0x398e2136)
Apr :: localhost NetworkManager[]: <info> address 10.0.0.132
Apr :: localhost NetworkManager[]: <info> plen (255.255.255.0)
Apr :: localhost NetworkManager[]: <info> gateway 10.0.0.2
Apr :: localhost NetworkManager[]: <info> server identifier 10.0.0.254
Apr :: localhost NetworkManager[]: <info> lease time
Apr :: localhost NetworkManager[]: <info> nameserver '10.0.0.2'
Apr :: localhost NetworkManager[]: <info> domain name 'localdomain'
Apr :: localhost NetworkManager[]: <info> (eno16777736): DHCPv4 state changed bound -> bound
Apr :: localhost dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost dbus-daemon: dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost systemd: Starting Network Manager Script Dispatcher Service...
Apr :: localhost dhclient[]: bound to 10.0.0.132 -- renewal in seconds.
Apr :: localhost dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost dbus-daemon: dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost systemd: Started Network Manager Script Dispatcher Service.
Apr :: localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736
Apr :: localhost systemd: Started Session of user root.
Apr :: localhost systemd: Starting Session of user root.
Apr :: localhost dhclient[]: DHCPREQUEST on eno16777736 to 10.0.0.254 port (xid=0x398e2136)
Apr :: localhost dhclient[]: DHCPACK from 10.0.0.254 (xid=0x398e2136)
Apr :: localhost NetworkManager[]: <info> address 10.0.0.132
Apr :: localhost NetworkManager[]: <info> plen (255.255.255.0)
Apr :: localhost NetworkManager[]: <info> gateway 10.0.0.2
Apr :: localhost NetworkManager[]: <info> server identifier 10.0.0.254
Apr :: localhost NetworkManager[]: <info> lease time
Apr :: localhost NetworkManager[]: <info> nameserver '10.0.0.2'
Apr :: localhost NetworkManager[]: <info> domain name 'localdomain'
Apr :: localhost NetworkManager[]: <info> (eno16777736): DHCPv4 state changed bound -> bound
Apr :: localhost dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost systemd: Starting Network Manager Script Dispatcher Service...
Apr :: localhost dbus-daemon: dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost dhclient[]: bound to 10.0.0.132 -- renewal in seconds.
Apr :: localhost dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost dbus-daemon: dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost systemd: Started Network Manager Script Dispatcher Service.
Apr :: localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736
Apr :: localhost dhclient[]: DHCPREQUEST on eno16777736 to 10.0.0.254 port (xid=0x398e2136)
Apr :: localhost dhclient[]: DHCPACK from 10.0.0.254 (xid=0x398e2136)
Apr :: localhost NetworkManager[]: <info> address 10.0.0.132
Apr :: localhost NetworkManager[]: <info> plen (255.255.255.0)
Apr :: localhost NetworkManager[]: <info> gateway 10.0.0.2
Apr :: localhost NetworkManager[]: <info> server identifier 10.0.0.254
Apr :: localhost NetworkManager[]: <info> lease time
Apr :: localhost NetworkManager[]: <info> nameserver '10.0.0.2'
Apr :: localhost NetworkManager[]: <info> domain name 'localdomain'
Apr :: localhost NetworkManager[]: <info> (eno16777736): DHCPv4 state changed bound -> bound
Apr :: localhost dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost systemd: Starting Network Manager Script Dispatcher Service...
Apr :: localhost dbus-daemon: dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost dhclient[]: bound to 10.0.0.132 -- renewal in seconds.
Apr :: localhost dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost dbus-daemon: dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost systemd: Started Network Manager Script Dispatcher Service.
Apr :: localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736
Apr :: localhost dhclient[]: DHCPREQUEST on eno16777736 to 10.0.0.254 port (xid=0x398e2136)
Apr :: localhost dhclient[]: DHCPACK from 10.0.0.254 (xid=0x398e2136)
Apr :: localhost NetworkManager[]: <info> address 10.0.0.132
Apr :: localhost NetworkManager[]: <info> plen (255.255.255.0)
Apr :: localhost NetworkManager[]: <info> gateway 10.0.0.2
Apr :: localhost NetworkManager[]: <info> server identifier 10.0.0.254
Apr :: localhost NetworkManager[]: <info> lease time
Apr :: localhost NetworkManager[]: <info> nameserver '10.0.0.2'
Apr :: localhost NetworkManager[]: <info> domain name 'localdomain'
Apr :: localhost NetworkManager[]: <info> (eno16777736): DHCPv4 state changed bound -> bound
Apr :: localhost dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost systemd: Starting Network Manager Script Dispatcher Service...
Apr :: localhost dbus-daemon: dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost dhclient[]: bound to 10.0.0.132 -- renewal in seconds.
Apr :: localhost dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost dbus-daemon: dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost systemd: Started Network Manager Script Dispatcher Service.
Apr :: localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736
Apr :: localhost dhclient[]: DHCPREQUEST on eno16777736 to 10.0.0.254 port (xid=0x398e2136)
Apr :: localhost dhclient[]: DHCPACK from 10.0.0.254 (xid=0x398e2136)
Apr :: localhost NetworkManager[]: <info> address 10.0.0.132
Apr :: localhost NetworkManager[]: <info> plen (255.255.255.0)
Apr :: localhost NetworkManager[]: <info> gateway 10.0.0.2
Apr :: localhost NetworkManager[]: <info> server identifier 10.0.0.254
Apr :: localhost NetworkManager[]: <info> lease time
Apr :: localhost NetworkManager[]: <info> nameserver '10.0.0.2'
Apr :: localhost NetworkManager[]: <info> domain name 'localdomain'
Apr :: localhost NetworkManager[]: <info> (eno16777736): DHCPv4 state changed bound -> bound
Apr :: localhost dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost dbus-daemon: dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost systemd: Starting Network Manager Script Dispatcher Service...
Apr :: localhost dhclient[]: bound to 10.0.0.132 -- renewal in seconds.
Apr :: localhost dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost dbus-daemon: dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost systemd: Started Network Manager Script Dispatcher Service.
Apr :: localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736
Apr :: localhost systemd: Started Session of user root.
Apr :: localhost systemd: Starting Session of user root.
Apr :: localhost dhclient[]: DHCPREQUEST on eno16777736 to 10.0.0.254 port (xid=0x398e2136)
Apr :: localhost dhclient[]: DHCPACK from 10.0.0.254 (xid=0x398e2136)
Apr :: localhost NetworkManager[]: <info> address 10.0.0.132
Apr :: localhost NetworkManager[]: <info> plen (255.255.255.0)
Apr :: localhost NetworkManager[]: <info> gateway 10.0.0.2
Apr :: localhost NetworkManager[]: <info> server identifier 10.0.0.254
Apr :: localhost NetworkManager[]: <info> lease time
Apr :: localhost NetworkManager[]: <info> nameserver '10.0.0.2'
Apr :: localhost NetworkManager[]: <info> domain name 'localdomain'
Apr :: localhost NetworkManager[]: <info> (eno16777736): DHCPv4 state changed bound -> bound
Apr :: localhost dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost systemd: Starting Network Manager Script Dispatcher Service...
Apr :: localhost dbus-daemon: dbus[]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr :: localhost dhclient[]: bound to 10.0.0.132 -- renewal in seconds.
Apr :: localhost dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost dbus-daemon: dbus[]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr :: localhost systemd: Started Network Manager Script Dispatcher Service.
Apr :: localhost nm-dispatcher: Dispatching action 'dhcp4-change' for eno16777736
grep dbus 3.log |sed -r 's/^.*host (.*): .*$/\1/g'|sed 's/dbus-daemon: //g'|awk '{print $1}'
过滤关键字 搜索
[root@admin ~]# ss -nat
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN ::: :::*
LISTEN *: *:*
LISTEN ::: :::*
LISTEN *: *:*
LISTEN 127.0.0.1: *:*
LISTEN *: *:*
LISTEN *: *:*
LISTEN ::: :::*
LISTEN ::: :::*
LISTEN *: *:*
LISTEN ::: :::*
LISTEN ::: :::*
LISTEN *: *:*
LISTEN *: *:*
LISTEN ::: :::*
ESTAB 118.188.20.3: 221.122.103.135:
TIME-WAIT 172.16.16.2: 172.16.16.9:
TIME-WAIT 172.16.16.2: 172.16.16.9:
TIME-WAIT 172.16.16.2: 172.16.16.9:
TIME-WAIT 172.16.16.2: 172.16.16.9:
TIME-WAIT 172.16.16.2: 172.16.16.9:
TIME-WAIT 172.16.16.2: 172.16.16.9:
TIME-WAIT 172.16.16.2: 172.16.16.9:
用sed取第一列:
ss -ant|sed 's/[ \t].*//'
取出第一行的指定字符串,后项引用 磁盘使用率
df |sed -nr '/^\/dev/s/([^ ]+).*$/\1/p'
df |sed -nr '/^\/dev/s/.* (.*)%.*/\1/p'
grep、awk、sed的巩固练习的更多相关文章
- Linux三剑客-grep || awk || sed
grep是一个强大的文本搜索工具 命令格式: grep [option] pattren file -a 将二进制文档以文本方式处理 -c 计算找到的符合行的次数 -i 忽略大小写 -n 顺便 ...
- Linux查找命令:grep,awk,sed
grep grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具 ...
- grep/awk/sed 或者 并且 否定
Grep 'OR' Operator Find all the lines in a file, that match any of the following patterns. Using GRE ...
- 【Linux】linux中文本操作利器grep,awk,sed
grep命令 grep(global search regular expression)是一种强大的文本搜索工具,它可以使用正则表达式搜索文本,并把匹配的行打印出来.平时搜索文本中内容的时候是非常方 ...
- Linux四剑客find/grep/awk/sed
find ./ -name "*txt" -maxdepth 1 -type f -mtime -2 -exec mv {} ./bbb.txt \; 这条命令表示找当前目录(-m ...
- linux shell grep/awk/sed 匹配tab
处理文件的命令实在是多, sed, awk, grep等.遇到了需要匹配tab的情况, 记录一下. 例子如下:找出文本中第一列是1的行. 文本a 解法1 : 直接使用正则表达式, ^表示开头, \t表 ...
- linux相关(find/grep/awk/sed/rpm)
如何查找特定的文件: find :在指定目录下查找文件 find -name "filename" :从当前目录查找文件 find / -name "filename&q ...
- 正则表达式(grep,awk,sed)和通配符
1. 正则表达式 1. 什么是正则表达式? 正则表达式就是为了处理大量的字符串而定义的一套规则和方法. 通过定义的这些特殊符号的辅助,系统管理员就可以快速过滤,替换或输出需要的字符串. Linux正则 ...
- 【linux系统】命令学习(五)linux三剑客 grep \ awk \ sed
grep----基于正则表达式查找满足条件的行 1.内容检索 获取行 grep pattern file 获取内容 grep -o pattern file 获取上下文grep -A -B -C pa ...
- Linux文本三剑客超详细教程---grep、sed、awk
awk.grep.sed是linux操作文本的三大利器,合称文本三剑客,也是必须掌握的linux命令之一.三者的功能都是处理文本,但侧重点各不相同,其中属awk功能最强大,但也最复杂.grep更适合单 ...
随机推荐
- C语言之将弧度值转换为角度值
#include<stdio.h> #include<stdlib.h> #define pi 3.141592 void conver_radian(float radian ...
- win10x64 批处理自动安装打印机
系统版本:Windows 10企业版 64位(10.0 ,版本17134)- 中文(简体) 话不多说,直接上脚本: REM 提升管理员权限 @echo off chcp 65001 >nul s ...
- spring整合redis使用RedisTemplate的坑Could not get a resource from the pool
一.背景 项目中使用spring框架整合redis,使用框架封装的RedisTemplate来实现数据的增删改查,项目上线后,我发现运行一段时间后,会出现异常Could not get a resou ...
- elk部署之前注意事项
注意事项: 1.不能使用root用户登录,需要是用root 之外的用户登录到系统. 2.centos系统 运行内存不能小于2G,若低于2G需要修改jvm. vi {jvm_home}/config/ ...
- 重写Sink合并多行
flume1.6+elasticsearch6.3.2 Pom <dependencies> <dependency> <groupId>junit</gro ...
- celery 和 haystack
celery 是分布式异步框架 haystack 是全文检索 只能在Django中用. 一.什么是celery? ---->它是Python写的,所以只支持Python使用.但是消 ...
- 汉诺塔I && II
汉诺塔I 题目链接:https://www.nowcoder.com/questionTerminal/7d6cab7d435048c4b05251bf44e9f185 题目大意: 略 分析: 利用汉 ...
- React react-fastclick-alt 移动端点击
1. Install npm install --save-dev react-fastclick-alt 2. 用法 将元素或者component放在 <FastClick>...&l ...
- DAY29、元类
一.eval内置函数eval内置函数的使用场景: 1.执行字符串会得到相应的执行结果 2.一般用于类型转换,得到dict.list.tuple例: dic_str = ''{'a':1,'b':2}' ...
- 【LUOGU???】WD与积木 NTT
题目大意 把 \(n\) 个有标号物品分到一些有标号的箱子中且不允许为空,问期望箱子的数量. 多组询问. \(n\leq 100000\) 题解 记 \(f_i\) 为 \(i\) 个有标号物品分到一 ...