Skip to content

Instantly share code, notes, and snippets.

@briandoll
Created July 21, 2008 22:33
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 briandoll/384 to your computer and use it in GitHub Desktop.
Save briandoll/384 to your computer and use it in GitHub Desktop.
awk ldap query to yaml
# 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