in reply to building an ldif from 2 files
You'd endear yourself more if you followed the (simple) local formatting conventions.
Lots of room for error checking, but ought to work. (Note: This writes the file directly. No redirection required.)
#! perl -slw use strict; use constant batchdir => "e:\meta"; use constant { infile => batchdir . "\DDNs3"; nfile2 => batchdir . "\DDNsUid2"; outfile => "DDNs3.ldif", ## Assume outfile n current dir per .cmd }; unlink outfile; ## If there delete it; silently do nothing if not. open DN, '<', infile or die $!; open UID, '<', infile2 or die $!; open OUT, '>', outfile or die $!; while( <DN> ) { chomp; print OUT "dn: $_"; print OUT "changetype: notify"; print OUT "replace: employeeNumber"; chomp( my $empNo = <UID> ); print OUT "employeeNumber: $empNo"; } close OUT; close UID, close DN; __END__ @echo on ::Set BATCH Input Directory set batchdir=e:\meta ::Set the input file containing the list set infile=%batchdir%\DDNs3 set infile2=%batchdir%\DDNsUid2 ::If exists, we remove output file rm DDNs3.ldif ::For loop below process each line in the input list. :uid FOR /F "tokens=* delims=" %%i IN (%infile%) do ( echo dn: %%i echo changetype: modify echo replace: employeeNumber call :loop2 ) goto :eof :loop2 FOR /F "tokens=* delims=" %%k IN (%infile2%) do ( echo employeeNumber: %%k echo. call :uid ) :eof
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: building an ldif from 2 files
by rfransix (Novice) on May 26, 2010 at 16:44 UTC | |
by BrowserUk (Patriarch) on May 26, 2010 at 16:52 UTC |