# 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) } }