diff --git a/tests/scripts/acfiltersort.sh b/tests/scripts/acfiltersort.sh
new file mode 100755
index 0000000000..fe7b9474cc
--- /dev/null
+++ b/tests/scripts/acfiltersort.sh
@@ -0,0 +1,18 @@
+#! /bin/sh
+# $OpenLDAP$
+## This work is part of OpenLDAP Software .
+##
+## Copyright 1998-2004 The OpenLDAP Foundation.
+## All rights reserved.
+##
+## Redistribution and use in source and binary forms, with or without
+## modification, are permitted only as authorized by the OpenLDAP
+## Public License.
+##
+## A copy of this license is available in the file LICENSE in the
+## top-level directory of the distribution or, alternatively, at
+## .
+#
+# Strip comments
+#
+egrep -iv '^#' | awk -f $LDIFSORT
diff --git a/tests/scripts/defines.sh b/tests/scripts/defines.sh
index 2a4aca3887..ec2c62f8a9 100755
--- a/tests/scripts/defines.sh
+++ b/tests/scripts/defines.sh
@@ -93,6 +93,8 @@ CLIENTDIR=../clients/tools
LDIFFILTER=$SRCDIR/scripts/acfilter.sh
CONFFILTER=$SRCDIR/scripts/conf.sh
+LDIFFILTERSORT=$SRCDIR/scripts/acfiltersort.sh
+LDIFSORT=$SRCDIR/scripts/ldifsort.awk
SLAPADD="../servers/slapd/slapd -Ta $LDAP_VERBOSE"
SLAPCAT="../servers/slapd/slapd -Tc $LDAP_VERBOSE"
diff --git a/tests/scripts/ldifsort.awk b/tests/scripts/ldifsort.awk
new file mode 100644
index 0000000000..5e8f9f619b
--- /dev/null
+++ b/tests/scripts/ldifsort.awk
@@ -0,0 +1,51 @@
+# Parses LDIF files, eliminating contnuations, and sorts
+# Author: Pierangelo Masarati
+
+func parse_line( line ) {
+ getline;
+
+ while ($0 != "") {
+ c = substr($0, 1, 1);
+ if (c == "#") {
+ continue;
+ }
+ if (c != " ") {
+ break;
+ }
+
+ line = line substr($0, 2, length($0));
+
+ getline;
+ }
+
+ return line;
+}
+
+/^dn: / {
+ /* FIXME: works only if DN is on one line... */
+ dn = $0;
+ dn = parse_line(dn);
+
+ while (1) {
+ if ($0 == "") {
+ break;
+ }
+ line = $0;
+ line = parse_line(line);
+ attrs[line] = line
+ }
+
+ entry[dn] = dn "\n";
+ n = asort(attrs);
+ for (i = 1; i <= n; i++) {
+ entry[dn] = entry[dn] attrs[i] "\n"
+ }
+ delete attrs
+}
+
+END {
+ n = asort(entry);
+ for (i = 1; i <= n; i++) {
+ print entry[i];
+ }
+}
diff --git a/tests/scripts/sql-test900-write b/tests/scripts/sql-test900-write
index c225490f52..bb85af0f83 100755
--- a/tests/scripts/sql-test900-write
+++ b/tests/scripts/sql-test900-write
@@ -315,9 +315,9 @@ EOMODS
fi
echo "Filtering ldapsearch results..."
- . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
+ . $LDIFFILTERSORT < $SEARCHOUT > $SEARCHFLT
echo "Filtering modified ldif..."
- . $LDIFFILTER < $SQLWRITE > $LDIFFLT
+ . $LDIFFILTERSORT < $SQLWRITE > $LDIFFLT
echo "Comparing filter output..."
$CMP $SEARCHFLT $LDIFFLT > $CMPOUT