PlayZoneUK Posted November 28, 2010 Share Posted November 28, 2010 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 Words of Wisdom and Favourite Quotes: '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!' 'The truth that humanity has never been able to grasp, is that death may be the only absolute freedom there is!' 'I've run out of places to put the brush... what do you suggest?' Link to comment Share on other sites More sharing options...
Malkey Posted November 28, 2010 Share Posted November 28, 2010 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 ') Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now