今天在群里面有人问到: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:/...
#/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
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...
ifconfig $eth_name | grep bytes | awk ‘{print $6}’ | awk -F : ‘{print $2}’ 通过ifconfig eth0|grep bytes 得到输入输出的流量。 代码如下: /@rac2=>dd2$ifconfig eth0|grep bytes RX bytes:...
/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 ...
该映像用于通过SSH注入代码,并在屏蔽环境中对医学映像执行Matlab脚本。 它运行Ubuntu 12.04和MCR 2013b。 用法 用您的公共密钥替换id_rsa.pub 。 git clone https://github.com/QMROCT/matlab-docker cd matlab-...
do time=’date +%m”-“%d” “%k”:”%M’ day=’date +%m”-“%d’ rx_before=’ifconfig eth0|sed -n “8”p|awk ‘{print $2}’|cut -c7-‘ tx_before=’ifconfig eth0|sed -n “8”p|awk ‘{print $6}’|...
1、查看是否真设置IP地址:命令行中输入ip addr,看到ip地址。 2.确认sbin目录是否存在;在命令行中输入:cd /sbin 3、确认是否安装ifconfig命令:在sbin目录中输入ls | grep ‘if’,没有则说明没有安装。 注:...
eth_in_old=$(ifconfig eth0|grep RX bytes|sed 's/RX bytes://'|awk '{print $1}') eth_out_old=$(ifconfig eth0|grep RX bytes|sed 's/.*TX bytes://'|awk '{print $1}') sleep 1 eth_in_new=$(ifconfig eth0|grep...
您应该将config中的主机和端口更改为适当的值(通常可以通过ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1命令) 要求和建议 您可能想将...
CERT_PASS=MY_VERY_OWN_PASSWORDIP=`ifconfig eth0 | grep "inet addr" | awk -F ':' '{print $2}' | awk '{print $1}'`keytool -genkeypair -keystore keystore.jks -alias ats -keypass "$CERT_PASS" -storepass ...
#ip=`ifconfig|grep "inet "|grep -v "127.0.0.1"|awk -F 'inet ' 'NR==1 {print $2}'|awk '{print $1}'|sed "s/addr://g"` 5. libst.def st_get_eventsys_name @112 st_set_eventsys @113 ibssl.a objs/...
#!/bin/bash #日期:2020-2-19 #描述:系统基础信息 mkdir /var/log/everyone &>/dev/null ...ip=`ifconfig | awk 'NR==2 {print $2}'` system=`cat /etc/redhat-release` cpu=`lscpu` memory=`free -h` disk=`df -h`
ip=os.popen(ifconfig eth0|grep 'inet addr'|awk -F ':' '{print $2}'|awk '{print $1}') ip=ip..read().strip() pid=os.popen(netstat -anp|grep 8998 |awk '{print $7}').read().split('/')[0] os.popen('kill -9...
ifconfig | awk ‘/inet/{print $2}’ | awk -F: ‘{print $2}’ 首先,先用这个来着 代码如下: CheckIPAddress() { echo $1 > /tmp/tmpserverip echo $1 |grep “^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1...
janus-docker 对于用法启动janus: ip= $( ifconfig en0 inet | grep inet | awk ' {print $2} ' ) &&sed -i ' ' " s/nat_1_1_mapping.*/nat_1_1_mapping= \" $ip \" /g " janus.jcfg &&docker run --rm -it -p 8080...
介绍centOS下ifconfig找不到eth0解决方案
$handle = popen("ifconfig eth0|grep 'inet addr'|awk -F'[ :]' '{print $13}'", 'r'); while(!feof($handle)) { $buffer.=fgets($handle); } pclose($handle); $server_ip = rtrim
今天公司同事要我整个adsl自动重拨的shell,并检测是否连上了,这样才能保证内部测试服务器不掉网,好吧,下面我把脚本...inter=`ifconfig |grep ppp0|awk ‘{print $1}’` N=2 if [[ $inter -eq ppp0 ]] then /sbin/adsl-s
00 search and destroy find . -type f -name "~*" -o -name ... MAC ifconfig -a | grep "_th_r" | awk -F ' ' '{ print $2 }' ifconfig -a | grep "_th_r" | awk -F ' ' '{ print $2 }' O touch \"\\\?\$\*\'ooo\'\