grep
filter row
parameter | meaning |
---|---|
-v | reverse election |
Take ifconfig ens33 sample data as an example
[atguigu@hadoop102 ~]$ ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.102 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fec3:515e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c3:51:5e txqueuelen 1000 (Ethernet)
RX packets 125370 bytes 17980197 (17.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 952591 bytes 1790545604 (1.6 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[atguigu@hadoop102 ~]$ ifconfig ens33|grep inet
inet 192.168.10.102 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fec3:515e prefixlen 64 scopeid 0x20<link>
[atguigu@hadoop102 ~]$ ifconfig ens33|grep inet|grep -v inet6
inet 192.168.10.102 netmask 255.255.255.0 broadcast 192.168.10.255
cut
Filter Columns/Cut Columns
parameter | meaning |
---|---|
-f | Column number, which column to extract eg: -f 1 |
-d | Delimiter eg: -d ":" |
-c | Specify specific characters eg: -c 1-6 |
[atguigu@hadoop102 ~]$ ifconfig ens33|grep inet|cut -d " " -f 10
192.168.10.102
fe80::20c:29ff:fec3:515e
[atguigu@hadoop102 ~]$ ifconfig ens33|grep inet|grep -v inet6|cut -c 14-27
192.168.10.102
sort
sort by row
parameter | meaning |
---|---|
-n | Sort by value |
-t | Separator eg: -t: (split by:) |
-r | reverse order reverse order |
-k | Specify to sort by which column |
[atguigu@hadoop102 ~]$ sort -t : -nrk 3 sort.txt
bb:40:5.4
bd:20:4.2
cls:10:3.5
xz:50:2.3
ss:30:1.6
awk
Read the file line by line, slice each line with spaces as the default delimiter, and then analyze and process the cut parts.
awk [option parameters] 'pattern1{action1} pattern2{action2}...' filename
pattern: Indicates what AWK is looking for in the data, which is the matching pattern
action: A series of commands executed when the matching content is found
parameter | meaning |
---|---|
-F | The specified delimiter defaults to a space |
-v | Assign a custom variable |
[atguigu@hadoop102 ~]$ ifconfig ens33 |grep inet |grep -v inet6
inet 192.168.10.102 netmask 255.255.255.0 broadcast 192.168.10.255
[atguigu@hadoop102 ~]$ ifconfig ens33 |grep inet |grep -v inet6|awk '{print $2}'
192.168.10.102
$NF represents the last field
[atguigu@hadoop102 ~]$ ifconfig ens33 |grep inet |grep -v inet6|awk '{print $NF}'
192.168.10.255
$0 represents the whole line
NR== selected line
[atguigu@hadoop102 ~]$ ifconfig ens33 |awk 'NR==2{print $0}'
inet 192.168.10.102 netmask 255.255.255.0 broadcast 192.168.10.255
sed
Here we only talk about replacement: Syntax: sed 's/string to be replaced/new string/g'
[atguigu@hadoop102 ~]$ ifconfig ens33 |grep inet |grep -v inet6|awk '{print $2}'|sed 's/102/103/g'
192.168.10.103
xargs
Convert standard input data into command-line acceptance numbers
# -t-t 强制分配为伪终端,即使标准输入不是终端
[atguigu@hadoop102 ~]$ ifconfig ens33 |grep inet |grep -v inet6|awk '{print $2}'|sed 's/102/103/g'|xargs ssh -tt
Last login: Fri Sep 23 12:53:40 2022 from 192.168.10.1
[atguigu@hadoop103 ~]$