Solved

transform ldif to CSV with selected values

Posted on 2013-11-14
2
488 Views
Last Modified: 2013-12-04
Hello all,
I need to transform an ldif file consisting of multiple records like this..

cn: Jon Sasquatch
lockoutTime: 0
url: GPS Inquiry/HORIZ
url: GIS Inquiry/HORIZ
url: CSR/HORIZ
url: GPS Inquiry/WLPT

Where I need to capture the cn and each url line and I would like to have this in csv format

Jon Sasquatch,GPS Inquiry/HORIZ,GIS Inquiry/HORIZ
Jon Sasquatch,GPS Inquiry/HORIZ,GIS Inquiry/HORIZ


I can get the indiviual lines with a begin or ^ function but its the next begin and grouping that I cannot figure out as well as the CSV formatting.

I'd prefer to use VBA, awk, sed, or shell if possible, but can look at other options.
Thank you
0
Comment
Question by:ruggerrick
  • 2
2 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 39650961
why would you want to repeat the first two entries and ignore the second two entries?
0
 
LVL 45

Accepted Solution

by:
aikimark earned 150 total points
ID: 39651986
Once you've read the LDIF file (text is expected to be in a variable. strLDIFtext used as variable name in the following example), you can parse and process the text as follows.  I left a comment where you would put code to output the line of data.
dim oRE as object
dim oMatches as object, oMatch as object
dim strOut
set oRE = createobject("vbscript.regexp")
oRE.Global = True
oRE.Pattern = "(cn|url): (.*)"
if oRE.Test(strLDIFtext) Then
  set oMatches = oRE.Execute(strLDIFtext)
  for each oMatch in oMatches
    if oMatch.Submatches(0) = "url" then
      if len(strOut) <> 0 Then
        'output strOut to file
      end if
      strOut = oMatch.Submatches(1)
    else
      strOut = strOut & "," & oMatch.Submatches(1)
    endif
  next
else
  msgbox "LDIF data does not match expected pattern"
end if

Open in new window

Note: all the url values for each cn value appear on the same line.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question