`
tomhibolu
  • 浏览: 1431305 次
文章分类
社区版块
存档分类
最新评论

ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4 "/" $NF}'中"[ :]+" 是什么意思?

 
阅读更多
今天在群里面有人问到:ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4 "/" $NF}',我执行了一下

结果为192.168.55.229/255.255.255.0

但是现在有一个问题:那么[ :]+到底是什么意思呢?经过百度和群组的讨论,我们最终达成一致:

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

ps:

1。内建变量FS保存输入域分隔符的值,默认空格或tab。我们可以通过-F命令行选项修改FS的值。如$ awk -F: '{print $1,$5}' test将打印以冒号为分隔符的第一,第五列的内容。

2。可以同时使用多个域分隔符,这时应该把分隔符写成放到方括号中,如$awk -F'[ :\t]' '{print $1,$3}' test,表示以空格、冒号和tab作为分隔符。

下面我们来举个例子:

[root@master ~]# echo "inet addr:192.168.55.229 Bcast:192.168.55.255 Mask:255.255.255.0"|awk -F"[ :]" '{print $3}'
192.168.55.229
[root@master ~]#

[root@master ~]# echo "inet addr:192.168.55.229 Bcast:192.168.55.255 Mask:255.255.255.0"|awk -F"[ :]"'{print $2}'
addr
[root@master ~]#

分享到:
评论

相关推荐

    系统巡检脚本

    IPADDR=$(ifconfig eth0|grep 'inet addr'|awk -F '[ :]' '{print $13}') #环境变量PATH没设好,在cron里执行时有很多命令会找不到 export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/...

    Shell脚本获取本地网卡IP、mac地址、子网掩码、dns IP、外网IP

    #/usr/bin/env bash # Name: get_network_info.sh # Author: Purple_Grape # This is a script to gather network ...MAC=`LANG=C ifconfig $NIC | awk '/HWaddr/{ print $5 }' ` IP=`LANG=C ifconfig $NIC | awk

    gitlab安装脚本

    IP=`ifconfig eth0| grep "inet addr" | head -1 | cut -d : -f2 | awk '{print $1}'` ############yum update ,add epel ,add PIIAS source yum_ () { cd /etc/yum.repos.d/ yum install -y wget wget -O /etc/pki...

    linux运维常用命令

    命令:ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6- 或者 ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' 说明:该命令可以取 IP 地址,ifconfig 选项...

    取出IP地址linux

    2. **第一个`awk`命令**:`awk -v FS="inet addr:|Bcast" '{if (NR == 2) print $2}'`,设置字段分隔符为`inet addr:`或`Bcast`,并只打印第二行的第二个字段。 - **解析**:`NR == 2`表示当处理到第二行时打印第...

    统计网卡流量的两段shell脚本(使用ifconfig)

    ifconfig $eth_name | grep bytes | awk ‘{print $6}’ | awk -F : ‘{print $2}’ 通过ifconfig eth0|grep bytes 得到输入输出的流量。 代码如下: /@rac2=>dd2$ifconfig eth0|grep bytes RX bytes:...

    无人职守安装,kickstart

    mask=$(ifconfig eth0 | awk -F ":" '/Mask/{print $NF}') gw=$(route -n | grep eth0 | awk '/UG/{print $2}') echo $host sed -i "s/HOSTNAME\(.*\)/HOSTNAME=station$host.upl....

    几个常用的Linux监控脚本.docx

    rx_before='ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-' tx_before='ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-' sleep 2 rx_after='ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7...

    linux运维故障定位汇总linux服务器应用 电脑资料.pdf

    - `ifconfig eth0 |grep "i addr:" |awk '{print $2}'|cut -c 6-`获取eth0接口的IP地址。 - `free -m |grep "Mem" | awk '{print $2}'`显示内存总量(单位MB)。 10. **端口和连接状态**: - `stat -an -t | ...

    linux运维命令

    ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | cut -c 6- ``` **解析:** - `ifconfig eth0`: 查看eth0接口的信息。 - `grep "inet addr:"`: 获取IP地址所在的行。 - `awk '{print $2}'`: 打印第二列(IP...

    CentOS常用命令大全.docx

    * `ifconfig eth0 |grep inet addr: |awk {print $2}|cut -c 6-` * `ifconfig | grep inet addr: | grep -v 127.0.0.1 | cut -d: -f2 | awk { print $1}` 这些命令可以查看系统的 ip 地址、mac 地址、网关、dns 等...

    centOS下ifconfig找不到eth0解决方案

    CentOS下ifconfig找不到eth0解决方案 在CentOS系统中,如果使用ifconfig命令却找不到eth0网络接口,这可能会引起很多问题,如无法联网、无法设置IP地址等。今天,我们来解决这个问题。 原因分析 在CentOS系统中,...

    Debian常用命令

    - **示例**:`tcpdump -tnn -c20000 -i eth0 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr | awk '$1>100'`, 统计访问频率较高的前100个IP地址。 8. **ifconfig eth0 down** - **功能**...

    linux运维宝典

    11. **获取IP地址**:`ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-` 或 `ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'` 用于获取网络接口的IP地址。...

    获取磁盘IO与系统负载Load的shell脚本

    /bin/shhost=$(hostname)channel=$(hostname | sed ‘s/[0-9]//g’)runday=$(date +%Y-%m-%d)IPhost=$(/sbin/ifconfig | grep ‘inet addr:’| grep -v ‘127.0.0.1’ | cut -d: -f2 | awk ‘{ print $1}’)i=1 ...

    rsamatlab代码-matlab-docker:带有Matlab编译器运行时和SSHD的Docker映像

    该映像用于通过SSH注入代码,并在屏蔽环境中对医学映像执行Matlab脚本。 它运行Ubuntu 12.04和MCR 2013b。 用法 用您的公共密钥替换id_rsa.pub 。 git clone https://github.com/QMROCT/matlab-docker cd matlab-...

    从ifconfig中得到IP地址

    ifconfig | awk '/inet/{print $2}' | awk -F: '{print $2}' ``` 这段脚本分为两个步骤执行: 1. **第一步**:`ifconfig | awk '/inet/{print $2}'`,此步骤的作用是从`ifconfig`命令的输出中筛选包含`inet`关键字...

    Linux教程-linux-文本处理-grep.docx

    * ifconfig | grep -E '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}':从 ifconfig 命令的输出中搜索包含 IP 地址的行 * ifconfig | grep -E '([0-9]{1,3}.){3}[0-9]{1,3}':从 ifconfig 命令的输出中搜索包含 IP ...

    成功在Linux下安装TP-LINK TL-WN322G+ 54M无线USB网卡驱动

    ifconfig eth1 192.168.1.188 netmask 255.255.255.0 route add default gw 192.168.1.1 ``` 修改`/etc/resolv.conf`文件添加DNS服务器地址: ```bash echo "nameserver 202.96.128.68" >> /etc/resolv.conf ...

Global site tag (gtag.js) - Google Analytics