Several methods of using text tools to intercept IP in Linux
1, using the awk tool
[[Email protected] data]# ifconfig ens33ens33: flags=4163<up,broadcast,running, multicast> mtu 1500 inet 192.168.1.140 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::8abb:80e7:a0ad:6463 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:52:25:a4 txqueuelen 1000 (Ethernet) rx packets 53417 bytes 5526762 (5.2&NBSP;MIB) rx errors 0 dropped 0 overruns 0 frame 0 TX packets 4618 bytes 627215 (612.5 KiB) &nbsP; tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0[[email protected] data]# ifconfig |awk -F " " ' nr==2 {print $2} ' 192.168.1.140
2, using the SED tool
[[Email protected] data]# ifconfig ens33ens33: flags=4163<up,broadcast,running, multicast> mtu 1500 inet 192.168.1.140 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::8abb:80e7:a0ad:6463 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:52:25:a4 txqueuelen 1000 (Ethernet) rx packets 53417 bytes 5526762 (5.2&NBSP;MIB) rx errors 0 dropped 0 overruns 0 frame 0 TX packets 4618 bytes 627215 (612.5 KiB) &nbsP; tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0[[email protected] data]# ifconfig |sed -n " 2p "|sed ' s#^.*net # #g ' |sed ' s# net.*$# #g ' 192.168.1.140 [[email protected] data]# welcome everyone to join the discussion together to study progress together I have been online
? Several ways to intercept IP using text tools in Linux