tags:

views:

17

answers:

2

Hi, i'm trying to build an ldif import file. I have 2 files, one with the DN and another with the employeeNumber, they match up line for line.

Here's the code that does not work:

@echo on

::Set BATCH Input Directory set batchdir=e:\Meta

::Set the input file containing the server list set infile=%batchdir%\DDNs3 set infile2=%batchdir%\DDNs4

::If exists, we remove output file Rm DDNs3.ldif

::For loop below process each line in the input list. FOR /F "tokens=* delims=" %%i IN (%infile%) do ( FOR /F "tokens=* delims=" %%k IN (%infile2%) do ( Echo dn: %%i Echo changetype: modify Echo replace: employeeNumber Echo employeeNumber: %%k ) ) >> DDNs3.ldif

I've tried several variations, including:

::For loop below process each line in the input list. FOR /F "tokens=* delims=" %%i IN (%infile%) do ( Echo dn: %%i Echo changetype: modify Echo replace: employeeNumber FOR /F "tokens=* delims=" %%k IN (%infile2%) do ( Echo employeeNumber: %%k echo. ) ) >> DDNs3.ldif

A: 

Use 2 for loops that loop over all lines in the file and write the output to an output file called e.g. ALL.TXT. Instead of just writing each line, prefix the lines of the first with 0001A, 0002A, 0003A, ... (assuming the files contain less than 9999 lines, if they contain more lines, use more 'zeroes'). Similarly, prefix the lines of the second file with 0001B, 0002B, 0003B, and so on.

Then use the SORT command to sort the contents of the resulting file.

Finally, use a for loop to loop over the resulting file and remove the first characters from the file again.

I don't know the full syntax of the FOR command, but this trick should be enough to help you further.

Patrick
A: 

Try Unix's cat tool.

mcandre