digitalexpl0it Posted October 9, 2015 Posted October 9, 2015 Hello,I am not sure where to start on this, but maybe some help from the community will help. I understand how to open a file and read it with autoit. My issue is this, I need to be able to select all the data on certain lines of the file by a keyword. I have a file that has multiple lines with the word "proxyAddresses:" that starts at the beginning of each line I want, there are other lines with other information I do not want. How can I select what I want and put it into an array? Example of filedn: CN=John Doe,OU=Techs,OU=Users,DC=foo,DC=bar changetype: add objectClass: top objectClass: person objectClass: organizationalPerson objectClass: user proxyAddresses: X500:/o=FooBar/ou=Exchange Administrative Group (FYDI)/cn=Re cipients/cn=Jogn Doec52 proxyAddresses: x500:/o=ExchangeLabs/ou=Exchange Administrative Group (FYSPDLT)/cn=Rec ipients/cn=3ab8cd9xxxxxxxxxxxxxxxxxxxxxf64e0c-John Do proxyAddresses: sip:jdoe@foobar.com proxyAddresses: smtp:jdoe@foobar.mail.onmicrosoft.com proxyAddresses: SMTP:jdoe@foobar.com
Iczer Posted October 9, 2015 Posted October 9, 2015 #include <Array.au3> $file = FileRead($filePath) $aproxyAddresses = StringRegExp($file,"(proxyAddresses:\V+)",3) _ArrayDisplay($aproxyAddresses)
Valuater Posted October 9, 2015 Posted October 9, 2015 (edited) remove the proxy text... #include <Array.au3> #include <File.au3> Local $aRetArray, $sFilePath = "Text.txt", $aArray[6], $count, $temp _FileReadToArray($sFilePath, $aRetArray) If @error Then Exit MsgBox(0, "Error", "Error") For $i = 1 To UBound($aRetArray) - 1 If StringInStr($aRetArray[$i], "proxyAddresses:") Then $temp = StringTrimLeft($aRetArray[$i], 15) $count += 1 $aArray[$count] = $temp EndIf Next _ArrayDisplay($aArray, "1D array - count", Default, 8) 8) Edited October 9, 2015 by Valuater
digitalexpl0it Posted October 9, 2015 Author Posted October 9, 2015 You guys rock, thanks that is what I was looking for
digitalexpl0it Posted October 9, 2015 Author Posted October 9, 2015 (edited) Have a little trouble not sure why I get an error at $aArray[$count] = StringStripWS($temp,1), it works then the last two that it fins it doesn't like the array. #include <Array.au3> #include <File.au3> local $user = @username RunWait(@ComSpec & ' /c ldifde -l proxyAddresses,objectClass -f ' & $user & '.txt -r "(proxyAddresses=smtp:' & $user & '@foobar.com)"') sleep(1000) Local $aRetArray, $sFilePath = $user & ".txt", $aArray[6], $count, $temp _FileReadToArray($sFilePath, $aRetArray) If @error Then Exit MsgBox(0, "Error", "Error") For $i = 1 To UBound($aRetArray) - 1 If StringInStr($aRetArray[$i], "proxyAddresses:") Then $temp = StringTrimLeft($aRetArray[$i], 15) $count += 1 $aArray[$count] = StringStripWS($temp,1) if ($aArray[$count] <> "") then msgbox(0,"",$aArray[$count]) endif EndIf NextText file dn: CN=John Doe,OU=Valley,OU=California,OU=Agencies,DC=foo,DC=bar changetype: add objectClass: top objectClass: person objectClass: organizationalPerson objectClass: user proxyAddresses: smtp:jdoe@xxxxvalley.com proxyAddresses: SMTP:johndoeN@xxxxvalley.com proxyAddresses: smtp:john-doe@foobar.com proxyAddresses: smtp:john.doe@foobar.com proxyAddresses: X500:/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Rec ipients/cn=3aec3f9078ee4a2a8c4c058d3df3f6c0-Elizabeth N proxyAddresses: smtp:jdoe@xxxxvalley.com proxyAddresses: smtp:john-doe@xxxxtent.mail.onmicrosoft.comN/M I see that the array was set to 6 and more data was beeing added, upped it to 10 and its fine Edited October 9, 2015 by digitalexpl0it
mikell Posted October 9, 2015 Posted October 9, 2015 You don't like Iczer's solution ? It's smart though :#include <Array.au3> $file = FileRead("test.txt") $aproxyAddresses = StringRegExp($file,"proxyAddresses:\h*(\S+)",3) _ArrayDisplay($aproxyAddresses)
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