Skip to content

Instantly share code, notes, and snippets.

@sdrik
Created September 22, 2019 09:18
Show Gist options
  • Select an option

  • Save sdrik/09866de2b48165de445ab564500d56af to your computer and use it in GitHub Desktop.

Select an option

Save sdrik/09866de2b48165de445ab564500d56af to your computer and use it in GitHub Desktop.
Prettify LDIF output in BASH
function ldif_decode {
if [[ "$1" =~ ^([^:]*)::\ (.*)$ ]]
then
echo "${BASH_REMATCH[1]}: $(base64 -d <<< "${BASH_REMATCH[2]}")"
else
echo "$1"
fi
}
function pretty_ldif {
local IFS=""
local prev_line=""
local line
while read -r line
do
if [ "${line:0:1}" = " " ]
then
prev_line="${prev_line}${line:1}"
else
ldif_decode "${prev_line}"
prev_line="${line}"
fi
done
ldif_decode "${prev_line}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment