awk - 冒号

1220阅读 0评论2020-11-04 fbwd
分类:LINUX

awk -F "[ :]+"

在rhel7中查看网卡地址:用如下命令
ifconfig ens33 |sed -n '2p' |awk -F '[ :]+' '{print $3}'
用默认的-F后面什么也不带没有效果

[ :]+这个是正则表达式,+表示一个或多个,这里就表示一个或多个空格或冒号

printf "1:2::3:::4::::5" | awk -F '[:]+' '{print $4}'
结果为 4
以1个或多个 :(空格或冒号)作为分隔符

转载于:https://blog.51cto.com/meiling/2307401

[root@centos01 init.d]# ifconfig ens33 |sed -n '2p' |awk -F '[ :]+' '{print $3}'
192.168.1.132
[root@centos01 init.d]#


上一篇:Monitor server status 监控服务器的活动状态
下一篇:shell中冒号的作用