Created
April 11, 2018 00:10
-
-
Save brianredbeard/69090291f40348e5a6daaa83d4757787 to your computer and use it in GitHub Desktop.
An awk script for LDIF processing
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
# Set the following values before any processing occurs: | |
# RS (record separator) to an empty line | |
# FS (field separator) to a newline | |
# OFS (output field separator) to a comma | |
BEGIN { RS = "" ; FS = "\n" ; OFS=","} | |
{ for (i=1;i<=NF;i++) { | |
# Add a line for each field to be extracted, replacing the field name in | |
# all three spots: | |
if ($i ~ "^cn: ") { cn=gensub("^cn: ","","g",$i) } | |
if ($i ~ "^title: ") { title=gensub("^title: ","","g",$i) } | |
if ($i ~ "^uidNumber: ") { uidNum=gensub("^uidNumber: ","","g",$i) } | |
if ($i ~ "^uid: ") { uid=gensub("^uid: ","","g",$i) } | |
} | |
# Output content in the event that the fields are not blank | |
if ( cn > "" && title > "" && uid > "" && uidNum > "" ) { | |
printf("%s\n title: %s\n uid: %s\n login: loginprefix-%s\n\n", cn, title, uid, uid) | |
} | |
# make sure to reset the values to blank | |
cn="" ; title = ""; uid="" ; uidNum="" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment