I am trying to parse dhcp.lease file from /tmp/dhcp.lease in openwrt .
root@OpenWrt:/# cat /tmp/dhcp.leases
1568953482 70:B3:D5:14:D0:31 192.168.3.51 device1 01:70:B3:D5:14:D0:31
2867821468 38:B8:EB:10:00:22 192.168.5.93 device2 01:38:B8:EB:10:00:22
8984532872 00:01:0A:33:11:33 192.168.5.44 CISCOee 01:00:01:0A:33:11:33
Where, 2nd column - MAC address , 3rd column - IP address and 4th column- Name
I want to run a shell script to parse No of devices
, MAC address
, IP address
and Device Name
from this dhcp.lease list .
sample output :
if there is 3 device
list is present in dhpcp.lease
file ,
I want to print output like :
3
70:B3:D5:14:D0:31/192.168.3.51/device1
38:B8:EB:10:00:22/192.168.5.93/device2
00:01:0A:33:11:33/192.168.5.44/CISCOee
and if no device list found , it should return
0
Can i do with simple file content iteration ? or any fast method like sed/awk ? Any sample code ?