[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

transform ldif to CSV with selected values

Posted on 2013-11-14
2
Medium Priority
?
553 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 46

Expert Comment

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

Accepted Solution

by:
aikimark earned 450 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Six Sigma Control Plans
Introduction to Processes

656 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