Portál AbcLinuxu, 9. května 2025 06:17
} lease 172.20.85.84 { starts 6 2005/02/05 15:54:51; ends 6 2005/02/05 15:56:51; tstp 6 2005/02/05 15:56:51; binding state free; hardware ethernet 00:a0:c9:9d:f7:23; uid "\001\000\240\311\235\367#"; client-hostname "test"; } lease 172.20.85.116 { starts 1 2005/02/07 17:38:58; ends 1 2005/02/07 18:38:58; tstp 1 2005/02/07 18:38:58; binding state free; hardware ethernet 00:0e:2e:08:c3:d9; uid "\001\000\016.\010\303\331"; client-hostname "test1"; }potrebuji to vyparsrovat do souboru jehoz vystup bude :
test 00:a0:c9:9d:f7:23 test1 00:0e:2e:08:c3:d9Zkousel jsem to s awk ale moc daleko jsem se nedostal
#!/usr/bin/perl while (<>) { if (/^lease/) { $hostname; $mac; while (<>) { if (/ethernet\s+([0-9a-fA-F\:]+)/) { $mac = $1; } elsif (/client-hostname\s+\"?([^\s\"]+)\"?/) { $hostname = $1; } elsif (/}/) { last; } } print "$hostname $mac\n"; } }
/^hardware/ { mac = $3 } /^client-hostname/ { out=$2" "mac ; gsub("[;\"]", "", out) ; print out }
sed -n '/hardware/N;/hardware/N;s/hardware ethernet \([0-9a-f:]*\);.*"\([^"]*\)";/\2 \1/p'
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.