I'm doing some placeholder replacements in various files that I'm feeding to ldapadd, to add new entries to an LDAP directory:
sed \
    -e 's/%%FOO%%/whatever/g' \
    -e 's/%%BAR%%/other thing/g \
    file1.ldif.template \
    file2.ldif.template \
    | ldapadd -x -D 'cn=admin,dc=example,dc=com' -W
The problem I'm having with this is that if there is not an empty line at the end of file1.ldif.template, the first record in file2 is concatenated to the last record in file1, and in ldif files different records should be separated by at least 1 newline.
Of course I could add an empty line at the end of file1, but that is very easy to fail in the future if some other developer (or their editors) remove the trailing newlines.
So to summarize. Current (simplified) sed output:
dn: cn=record1_file1,dc=example,dc=com
cn: record1_file1
dn: cn=record2_file1,dc=example,dc=com
cn: record2_file1
dn: cn=record1_file2,dc=example,dc=com
cn: record1_file2
dn: cn=record2_file2,dc=example,dc=com
cn: record2_file2
Desired (simplified) output:
dn: cn=record1_file1,dc=example,dc=com
cn: record1_file1
dn: cn=record2_file1,dc=example,dc=com
cn: record2_file1
dn: cn=record1_file2,dc=example,dc=com
cn: record1_file2
dn: cn=record2_file2,dc=example,dc=com
cn: record2_file2
I'm working on linux (fedora 21) using GNU sed. Portability is not a concern (but i'll prefer a portable solution over a GNU solution).