Re: Handling output from ldapsearch
- From: claird@xxxxxxxxx (Cameron Laird)
- Date: Mon, 30 Jun 2008 14:39:54 +0000
In article <soph64ptc8fcn326gugn0g9nn4j05o6lmq@xxxxxxx>,
Helmut Giese <hgiese@xxxxxxxxxxxxx> wrote:
On Mon, 30 Jun 2008 06:38:57 -0700 (PDT), utbloke@xxxxxxxxx wrote:.
"dn: CN=user01,CN=Users,DC=mynet,DC=localHi,
sAMAccountName: user01
dn: CN=user02,CN=Users,DC=mynet,DC=local
sAMAccountName: user02
dn: CN=user03,CN=Users,DC=mynet,DC=local
sAMAccountName: user03"
assuming that each result is on a line of its own and that the whole
string is in a variable 's' e.g. by means of a call like
set s [<your call here>]
the following should work:
---
# turn 's' into a list of lines
set lineLst [split $s \n]
# make sure you start with an empty list
set userLst {}
# iterate over the lines
foreach line $lineLst {
if { $line eq "" } {
# ignore empty lines
continue
}
# isolate the words in $line
set wordLst [split $line " "]
# ... and take the last one
lappend userLst [lindex $wordLst end]
}
puts "userLst: $userLst"
.
.
While I agree with Michael that you'll probably want to learn Tcl's
own LDAP binding, and my own instinct, like Helmut's, is to work on
a line-oriented basis, I want you to know that your efforts with
regular expressions *can* be fruitful. Consider this example:
set s "dn: CN=user01,CN=Users,DC=mynet,DC=local
sAMAccountName: user01
dn: CN=user02,CN=Users,DC=mynet,DC=local
sAMAccountName: user02
dn: CN=user03,CN=Users,DC=mynet,DC=local
sAMAccountName: user03"
set pattern {sAMAccountName: ([^\s]*)}
foreach {clause name} [regexp -all -inline $pattern $s] {
lappend result_list $name
}
puts "The result list is '$result_list'."
.
- References:
- Handling output from ldapsearch
- From: utbloke
- Re: Handling output from ldapsearch
- From: Helmut Giese
- Handling output from ldapsearch
- Prev by Date: clock format does not run in window service
- Next by Date: Re: Limiting resources used by scripts on web server
- Previous by thread: Re: Handling output from ldapsearch
- Next by thread: Re: Handling output from ldapsearch
- Index(es):