Update of /cvsroot/perl-ldap/ldap/contrib
In directory sc8-pr-cvs1:/tmp/cvs-serv18819
Modified Files:
ldifsort.pl
Log Message:
Added option to sort attributes within each entry.
Index: ldifsort.pl
===================================================================
RCS file: /cvsroot/perl-ldap/ldap/contrib/ldifsort.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ldifsort.pl 3 Jul 2001 19:30:02 -0000 1.1
+++ ldifsort.pl 24 Jun 2003 21:58:34 -0000 1.2
@@ -13,7 +13,7 @@
=head1 SYNOPSIS
-ldifsort.pl B<-k keyattr> [B<-nd>] file.ldif
+ldifsort.pl B<-k keyattr> [B<-and>] file.ldif
=over 4
@@ -23,6 +23,12 @@
specified, sorting is done by the full DN string, which can be composed of
different attributes for different entries.
+=item B<-a>
+
+Specifies that attributes within a given entry should also be sorted. This
+has the side effect of removing all comments and line continuations in the
+LDIF file.
+
=item B<-n>
Specifies numeric comparisons on the key attribute. Otherwise string
@@ -51,9 +57,10 @@
use strict;
my %args;
-getopts("k:nd", \%args);
+getopts("k:and", \%args);
my $keyattr = $args{k};
+my $sortattrs = $args{a};
my $ldiffile = $ARGV[0];
die "usage: $0 -k keyattr [-n] [-d] ldiffile\n"
@@ -96,7 +103,14 @@
foreach my $valuepos (@sorted) {
seek(LDIFH, $valuepos->[1], 0);
my $entry = <LDIFH>;
- print $entry;
- print "\n" if $entry !~ /\n\n$/;
+ if ($sortattrs) {
+ $entry =~ s/\n //mg; # collapse line continuations
+ my @lines = grep(!/^#/, split(/\n/, $entry));
+ my $dn = shift(@lines);
+ print "$dn\n", join("\n", sort @lines), "\n\n";
+ }
+ else {
+ print $entry;
+ print "\n" if $entry !~ /\n\n$/;
+ }
}
-
|