grep awk ignore character
awk, bash, grep, linux
Solution
Using `awk`
awk -F" |;" '/dhcp-server-identifier/ {print $3}' /var/lib/dhclient/dhclient-eth0.leases
192.168.75.1
Problem
I'm trying to grep the value of "option dhcp-server-identifier" which is 192.168.75.1; I'm not sure how to ignore the semicolon ";" at the end of IP address. ``` [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; } ``` I have tried the following ``` grep dhcp-server-identifier /var/lib/dhclient/dhclient-eth0.leases | awk '{print $3}' ``` result is 192.168.75.1; Thanks