Sign in to follow this  
Followers 0
PlayZoneUK

Read from Text File (LDIF Format) into an array

2 posts in this topic

Good evening all,

I'm hoping someone will be able to help me with a little scripting problem. I want to read an external text file (LDIF Format) into an array for me to manipulate. The problem I have is that some of the entries don’t have the additional attributes therefore the entry within the array needs to be empty. I have started a script which will read in the dn, but I'm not sure how to proceed with the other entries...

LDIF File: dns.ldif

#This LDIF file was generated by Novell's ICE and the LDIF destination handler.
version: 1

dn: cn=WORKSTATION-WHY,cn=example_co_uk,o=DHCP
changetype: add
dNIPRR:: AAEAAQABUYAABKOgaBY=

dn: cn=WORKSTATION-DO,cn=example_co_uk,o=DHCP

dn: cn=WORKSTATION-THINGS,cn=example_co_uk,o=DHCP

dn: cn=WORKSTATION-LIKE,cn=example_co_uk,o=DHCP

dn: cn=WORKSTATION-THIS,cn=example_co_uk,o=DHCP

dn: cn=WORKSTATION-KEEP,cn=example_co_uk,o=DHCP
changetype: add
dNIPRR:: AAEAAQABUYAABKOgaEA=

dn: cn=WORKSTATION-HAPPENING,cn=example_co_uk,o=DHCP

dn: cn=WORKSTATION-TO,cn=example_co_uk,o=DHCP
changetype: add
dNIPRR:: AAEAAQABUYAABKOgaDc=

dn: cn=WORKSTATION-ME,cn=leedsth_nhs_uk,o=DHCP
changetype: add
dNIPRR:: AAEAAQAAAAAABKOgb0Y=

Summary

I would like to achieve the following:

Array[0][0] = dn:

Array[0][1] = changetype:

Array[0][2] = dNIPRR::

Hope this makes sense and thanks in advance...

Here's what I have so far...

#include <String.au3>
#Include <Array.au3>

$sString = FileRead(@ScriptDir & '\dns.ldif')
$aArray = _StringBetween($sString, 'dn:\s', '\n', -1, 1)
If Not IsArray($aArray) And MsgBox(64, 'Info', 'No DNS Entries Found') Then Exit
Dim $aDNSEntry[UBound($aArray)][2]


For $iCC = 0 To UBound($aArray) - 1
    $aDNSEntry[$iCC][0] = 'dn: ' & $aArray[$iCC]
Next

_ArrayDisplay($aDNSEntry, 'Array Display ')

Exit

[u]Words of Wisdom and Favourite Quotes:[/u]'Nothing is impossible, despite what other people say and think, prove them wrong and show them what you can do!''Understanding is a three edged sword, your side, their side and the truth!''Nothing, I shoot ever gets back up again!''The truth that humanity has never been able to grasp, is that death may be the only absolute freedom there is!''The answer's no, now what's the question?''I hear what you're saying, but we're gonna do it my way!''You don't keep me informed' > 'But I sent you an e-Mail regarding this issue and you read it!' > 'oooh you can't expect an e-Mail to register!''How are you today?' > 'Fair to suicidal!'

Share this post


Link to post
Share on other sites



Try this.

#include <String.au3>
#include <Array.au3>

$sString = FileRead(@ScriptDir & '\dns.ldif')

$aArray = StringSplit($sString, @CRLF & @CRLF, 3)
If Not IsArray($aArray) Then
    MsgBox(64, 'Info', 'No DNS Entries Found')
    Exit
EndIf

Dim $aDNSEntry[UBound($aArray)][3]

For $iCC = 0 To UBound($aArray) - 1
    $aTemp = StringSplit(StringStripWS($aArray[$iCC], 3), @CRLF, 3)
    For $i = 0 To UBound($aTemp) - 1
        $aDNSEntry[$iCC][$i] = $aTemp[$i]
    Next
Next

_ArrayDisplay($aDNSEntry, 'Array Display ')

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0