Linux中过滤IP地址的9种方法
2016-01-09 16:26
501 查看
[root@localhost ~]# ifconfig
方法1:匹配 inet addr 这行;以冒号为分隔符,显示第2段;再次以空格为分隔符,显示第1段
[root@localhost ~]# ifconfig eth0 |grep 'inet addr' |cut -d: -f2 |cut -d" " -f1
方法2:匹配 inet addr 这行;以空替换从开头到 addr: 的字符串;再次以空替换从Bcast到结尾的字符串
[root@localhost ~]# ifconfig eth0 |grep 'inet addr' |sed 's/^.*addr://g' |sed 's/Bcast.*$//g'
方法3:匹配 inet addr 这行;以:或者空格作为分隔符,然后打印第4列
[root@localhost ~]# ifconfig eth0 |grep 'inet addr' |awk -F[:" "]+ '{print $4}'
方法4:匹配 inet addr 这行;以:作为分隔符,打印第2列,然后再打印第一列
[root@localhost ~]# ifconfig eth0 |grep 'inet addr' |awk -F: '{print $2}' |awk '{print $1}'
方法5:
[root@localhost ~]# ifconfig eth0|sed -nr '2s#^.*addr:(.*) Bcast.*$#\1#g'p
方法6:
[root@localhost ~]# ifconfig eth0 |awk '/inet addr:/ {print $2}' |awk -F: '{print $2}'
方法7:
[root@localhost ~]# ifconfig eth0 |awk '/inet addr:/ {print $2}' |awk -F: '{print $2}'
方法8:
[root@localhost ~]# ifconfig eth0 |awk 'NR==2 {print $2}' |awk -F: '{print $2}'
方法9:
[root@localhost ~]# ip add |awk -F '[ /]+' 'NR==8 {print $3}'
eth0 Link encap:Ethernet HWaddr DA:DE:BE:41:89:18 inet addr:192.168.150.53 Bcast:192.168.150.255 Mask:255.255.255.0 inet6 addr: fe80::d8de:beff:fe41:8918/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:184255445 errors:0 dropped:0 overruns:0 frame:0 TX packets:51947 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12701252470 (11.8 GiB) TX bytes:4422271 (4.2 MiB) Interrupt:17 |
[root@localhost ~]# ifconfig eth0 |grep 'inet addr' |cut -d: -f2 |cut -d" " -f1
192.168.150.53 |
[root@localhost ~]# ifconfig eth0 |grep 'inet addr' |sed 's/^.*addr://g' |sed 's/Bcast.*$//g'
192.168.150.53 |
[root@localhost ~]# ifconfig eth0 |grep 'inet addr' |awk -F[:" "]+ '{print $4}'
192.168.150.53 |
[root@localhost ~]# ifconfig eth0 |grep 'inet addr' |awk -F: '{print $2}' |awk '{print $1}'
192.168.150.53 |
[root@localhost ~]# ifconfig eth0|sed -nr '2s#^.*addr:(.*) Bcast.*$#\1#g'p
192.168.150.53 |
[root@localhost ~]# ifconfig eth0 |awk '/inet addr:/ {print $2}' |awk -F: '{print $2}'
192.168.150.53 |
[root@localhost ~]# ifconfig eth0 |awk '/inet addr:/ {print $2}' |awk -F: '{print $2}'
192.168.150.53 |
[root@localhost ~]# ifconfig eth0 |awk 'NR==2 {print $2}' |awk -F: '{print $2}'
192.168.150.53 |
[root@localhost ~]# ip add |awk -F '[ /]+' 'NR==8 {print $3}'
192.168.150.53 |
相关文章推荐
- Linux socket 初步
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- 基于 Linux 集群环境上 GPFS 的问题诊断
- 谁是桌面王者?Win PK Linux三大镇山之宝