Created
July 21, 2008 22:33
-
-
Save briandoll/384 to your computer and use it in GitHub Desktop.
awk ldap query to yaml
This file contains 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
# This is an awk script, but no awk colour coding is available here. | |
# | |
# input: an LDAP query pulling back the displayName and sAMAccountName properties | |
# for an entire ActiveDirectory forest | |
# | |
# output: yaml format of same data | |
# ex. | |
# 1: | |
# name: "Doll, Brian A" | |
# lan_id: "brian.a.doll" | |
# split on newline for fields | |
BEGIN { FS = "\n"; RS = "" } | |
# don't deal with incomplete records, gotta have 3 fields | |
NF == 3 { | |
name = $2 | |
lanid = $3 | |
# get rid of the prefixes | |
sub(/displayName\: /, "", name) | |
sub(/sAMAccountName\: /, "", lanid) | |
# escape the quotes on familiar names like "Tina" for Christina | |
gsub(/"/,"\\\"",name) | |
# get rid of the tabs | |
gsub(/[\t]/,"",name) | |
# skip numeric account names | |
if (!gsub(/^[0-9]/,"",name)) { | |
# print in yaml format | |
printf("%s:\n name: \"%s\"\n lan_id: \"%s\"\n", NR, name, lanid) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment