加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – grep awk忽略字符

发布时间:2020-12-13 23:56:29 所属栏目:Linux 来源:网络整理
导读:我正在尝试grep“option dhcp-server-identifier”的值,即192.168.75.1; 我不知道如何忽略分号“;”在IP地址的末尾. [root@localhost ~]# cat /var/lib/dhclient/dhclient-eth0.leaseslease {interface "eth0";fixed-address 192.168.75.54;option subnet-ma
我正在尝试grep“option dhcp-server-identifier”的值,即192.168.75.1;

我不知道如何忽略分号“;”在IP地址的末尾.

[root@localhost ~]# cat /var/lib/dhclient/dhclient-eth0.leases
lease {
interface "eth0";
fixed-address 192.168.75.54;
option subnet-mask 255.255.255.0;
option routers 192.168.75.1;
option dhcp-lease-time 4294967295;
option dhcp-message-type 5;
option domain-name-servers 192.168.75.1,8.8.8.8;
option dhcp-server-identifier 192.168.75.1;
option broadcast-address 192.168.75.255;
option host-name "centos-64-x86-64";
option domain-name "cs2cloud.internal";
renew 1 2081/12/15 18:43:55;
rebind 2 2132/12/30 03:09:24;
expire 6 2150/01/03 21:58:02;
}

我尝试了以下内容

grep  dhcp-server-identifier /var/lib/dhclient/dhclient-eth0.leases | awk '{print $3}'

结果是192.168.75.1;

谢谢

解决方法

使用awk

awk -F" |;" '/dhcp-server-identifier/ {print $3}' /var/lib/dhclient/dhclient-eth0.leases
192.168.75.1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读