Last active
August 29, 2015 14:21
-
-
Save ozzyjohnson/aaebe09b0168da5b7180 to your computer and use it in GitHub Desktop.
Convert exports from a NetWare DNS/DHCP server to CSV.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN { | |
FS = "=" | |
ipan = "" | |
at = "" | |
lt = "" | |
hn = "" | |
lu = "" | |
le = "" | |
mac = "" | |
ci = "" | |
c = "" | |
printf("ipan,at,lt,hn,lu,le,mac,ci,c\n"); | |
} | |
function trim(field) { | |
gsub(/\r/, "", field) | |
gsub(/^[ \t]+/, "", field) | |
return field; | |
} | |
function convertMAC(field) { | |
gsub(/\r/, "", field) | |
sub(/^[ \t]+/, "", field) | |
gsub(/ /, ":", field) | |
sub(/1:|6:|ff:/, "", field) | |
return field; | |
} | |
function trimCN(field) { | |
gsub(/cn=/,"", field) | |
return field; | |
} | |
/^\tIP Address Number/ { ipan = trim($2) } | |
/^\tAssignment Type/ { at = trim($2) } | |
/^\tLease Time/ { lt = trim($2) } | |
/^\tHost Name/ { hn = trim($2) } | |
/^\tLast Used/ { lu = trim($2) } | |
/^\tLease Expiration/ { le = trim($2) } | |
/^\tMAC Address/ { mac = convertMAC($2) } | |
/^\tClient Identifier/ { ci = trim($2) } | |
/^\tComment/ { c = trim($2) } | |
/^\[IP Address Configuration/ { | |
printf("%s,%s,%s,%s,%s,%s,%s,%s,%s\n",ipan,at,lt,hn,lu,le,mac,ci,c) | |
ipan = "" | |
at = "" | |
lt = "" | |
hn = "" | |
lu = "" | |
le = "" | |
cn = "" | |
mac = "" | |
ci = "" | |
c = "" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment