Skip to content

Instantly share code, notes, and snippets.

@ozzyjohnson
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozzyjohnson/aaebe09b0168da5b7180 to your computer and use it in GitHub Desktop.
Save ozzyjohnson/aaebe09b0168da5b7180 to your computer and use it in GitHub Desktop.
Convert exports from a NetWare DNS/DHCP server to CSV.
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