Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 76 lines (52 sloc) 1.633 kb
b66cbd0 Kartik Subbarao *** empty log message ***
kartiksubbarao authored
1 #! /usr/bin/perl
2
3 # $Id: ldifuniq.pl,v 1.1 2002/08/24 15:11:21 kartik_subbarao Exp $
4
5 =head1 NAME
6
7 ldifuniq.pl - Culls unique entries from a reference file with respect to a
8 comparison file.
9
10 =head1 DESCRIPTION
11
12 ldifuniq.pl takes as input two LDIF files, a reference file and a comparison
13 file. Each entry in the reference file is compared to its counterpart in the
14 comparison file. If it does not have a counterpart, or if the counterpart is
15 not identical, the reference entry is printed to standard output. Otherwise no
16 output is generated. This behavior is analogous to the -u option of the uniq
17 command.
18
19 =head1 SYNOPSIS
20
21 ldifuniq.pl reffile.ldif cmpfile.ldif
22
23 =head1 AUTHOR
24
25 Kartik Subbarao E<lt>subbarao@computer.orgE<gt>
26
27 =cut
28
29
30 use MIME::Base64;
31
32 use strict;
33
34
35 my $reffile = $ARGV[0];
36 my $cmpfile = $ARGV[1];
37
38 die "usage: $0 reffile cmpfile\n" unless $reffile && $cmpfile;
39
40 $/ = "";
41
42
43 sub getdn {
44 my $rec = shift;
45 my $dn;
46
47 1 while s/^(dn:.*)?\n /$1/im; # Handle line continuations
48 if (/^dn(::?) (.*)$/im) {
49 $dn = $2;
50 $dn = decode_base64($dn) if $1 eq '::';
51 }
52
53 $dn;
54 }
55
56 open(CMPFH, $cmpfile) || die "$cmpfile: $!\n";
57 my (%cmpdnpos, $pos); $pos = 0;
58 while (<CMPFH>) {
59 my $dn = getdn($_);
60 $cmpdnpos{$dn} = $pos;
61 $pos = tell;
62 }
63
64 open(REFFH, $reffile) || die "$reffile: $!\n";
65 while (<REFFH>) {
66 my $refrec = $_; $refrec .= "\n" if $refrec !~ /\n\n$/;
67 my $dn = getdn($refrec);
68 my $pos = $cmpdnpos{$dn};
69 if ($pos eq undef) {
70 print $refrec; next; # Not in cmpfile, print the entry.
71 }
72 seek(CMPFH, $pos, 0);
73 my $cmprec = <CMPFH>; $cmprec .= "\n" if $cmprec !~ /\n\n$/;
74 print $refrec if $refrec ne $cmprec;
75 }
Something went wrong with that request. Please try again.