Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 914  / 2 Years ago, sun, july 10, 2022, 7:48:56

I want to setup an alias or a script that will allow me show the DHCP bindings dnsmasq has.



$ cat /var/lib/misc/dnsmasq.leases
1411349054 08:11:96:e9:52:ec 192.168.1.96 W11837894 *

1411413528 b4:b6:76:0c:c9:4d 192.168.1.46 root-HP-9470m *

1411263016 00:1b:21:0e:f2:bd 192.168.1.219 root-Dell-DM061 *

1411357237 00:01:2e:4d:49:bd 192.168.1.31 ata *

1411263041 00:30:67:d2:25:65 192.168.1.51 root-TA75M *


I can take the 1st column and do a date -d @1411349054 (or awk '{print $1}' /var/lib/misc/dnsmasq.leases | awk '{ print strftime("%c")}')



Sun Sep 21 20:24:14 CDT 2014


I am looking for a way in awk to format like this:



Sun Sep 21 20:24:14 CDT 2014 08:11:96:e9:52:ec 192.168.1.96 W11837894 *

Mon Sep 22 14:18:48 CDT 2014 b4:b6:76:0c:c9:4d 192.168.1.46 root-HP-9470m *


Anyone have any ideas?


More From » bash

 Answers
7

You could try the below awk one-liner command,



awk 'NF{ $1=strftime("%c", $1);}1' file


OR



$ awk 'NF>1{ $1=strftime("%c", $1);}1' file
Monday 22 September 2014 06:54:14 AM IST 08:11:96:e9:52:ec 192.168.1.96 W11837894 *

Tuesday 23 September 2014 12:48:48 AM IST b4:b6:76:0c:c9:4d 192.168.1.46 root-HP-9470m *

Sunday 21 September 2014 07:00:16 AM IST 00:1b:21:0e:f2:bd 192.168.1.219 root-Dell-DM061 *

Monday 22 September 2014 09:10:37 AM IST 00:01:2e:4d:49:bd 192.168.1.31 ata *

Sunday 21 September 2014 07:00:41 AM IST 00:30:67:d2:25:65 192.168.1.51 root-TA75M *

[#23507] Tuesday, July 12, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
fulild

Total Points: 239
Total Questions: 103
Total Answers: 112

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
;