Solved

transform ldif to CSV with selected values

Posted on 2013-11-14
2
532 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Simple Linear Regression

691 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