Solved

transform ldif to CSV with selected values

Posted on 2013-11-14
2
458 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
Comment Utility
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
Comment Utility
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now