Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added option to sort attributes within each entry.

  • Loading branch information...
commit 49c7a4129a17ddcf72af006dc59ab4009b10085b 1 parent fdf63eb
Kartik Subbarao kartiksubbarao authored
Showing with 20 additions and 6 deletions.
  1. +20 −6 contrib/ldifsort.pl
26 contrib/ldifsort.pl
View
@@ -1,6 +1,6 @@
#! /usr/bin/perl
-# $Id: ldifsort.pl,v 1.1 2001/07/03 19:30:02 gbarr Exp $
+# $Id: ldifsort.pl,v 1.2 2003/06/24 21:58:34 kartik_subbarao Exp $
=head1 NAME
@@ -13,7 +13,7 @@ =head1 DESCRIPTION
=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 @@ =head1 SYNOPSIS
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 @@ =head1 AUTHOR
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 @@ sub cmpdn {
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$/;
+ }
}
-
Please sign in to comment.
Something went wrong with that request. Please try again.