Page 1 of 2 12>
Topic Options
#72442 - 2003-01-07 09:37 PM Extract part of a string
Anonymous
Unregistered


I have a string:

DOMAIN\UserName:(OI)(IO)(special access:)

And I want to extract JUST the user name. What is the easiest way to do this? I'm having a brain freeze! Thanks!!

Top
#72443 - 2003-01-07 09:46 PM Re: Extract part of a string
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
code:
$string = "DOMAIN\UserName:(OI)(IO)(special access:)"
$Account = split(split($string,":")[0],"\")
$Domain = $Account[0]
$Username = $Account[1]
? $Domain
? $Username

or more simply
code:
? split(split($string,":")[0],"\")[1]  



[ 07. January 2003, 22:00: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#72444 - 2003-01-07 09:47 PM Re: Extract part of a string
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See the KiXtart Manual under SPLIT() and SUBSTR().
_________________________
There are two types of vessels, submarines and targets.

Top
#72445 - 2003-01-07 09:52 PM Re: Extract part of a string
Anonymous
Unregistered


PERFECT!! You ROCK!! Thank for the QUICK response!! I thought I needed to use SPLIT, but couldn't figure out how!
Top
#72446 - 2003-01-07 09:54 PM Re: Extract part of a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Guess you could call that a double split!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#72447 - 2003-01-07 09:56 PM Re: Extract part of a string
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
with a cherry on top...
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#72448 - 2003-01-08 08:25 AM Re: Extract part of a string
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Funny,

I actually had Lonkero help me with a very similar string manipulation today via MSN chat.

Manual is okay for a single, but I too did not understand how to remove two or more items.

Top
#72449 - 2003-01-08 02:54 PM Re: Extract part of a string
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Very clever, Howard... [Cool]
_________________________
We all live in a Yellow Subroutine...

Top
#72450 - 2003-01-08 10:51 PM Re: Extract part of a string
Anonymous
Unregistered


That script WAS working pefect until I ran in to a bug. Can anyone help me again??

Script works fine that was posted by Howard Bullock until my varible changed a littel bit.

Works fine when it reads this line:

F:\AGG DOMAIN\USERNAME:(OI)(CI)F

But fails when it reads this line:

F:\CMD Files DOMAIN\USERNAME:F

The error is "Script error: array reference out of bounds! $NAMEGRP = $Account[1]

I modifed Howards script a little to fit my needs and this is what I'm actually using that's giving me the error. Any help would be WELL welcomed! Thanks!!

code:
IF INSTR ("$X", "D01\") <> 0
$Account = split(split($X,":")[0],"\")
$NAMEGRP = $Account[1]


Top
#72451 - 2003-01-08 10:58 PM Re: Extract part of a string
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You might want to go the slightly longer way as it makes debugging easier. Do each split separately and take a look at what you actually try to parse as 'DOMAIN\UserName:(OI)(IO)(special access:)' is definitely different from 'F:\CMD Files DOMAIN\USERNAME:F'
In the second case I'd do an instrrev to the first encounter space and use only the string after that spcae. The I can remove the stuff after the colon ':' and before the backslash '\'
However, you will also have to account for potential spaces in the username.
_________________________
There are two types of vessels, submarines and targets.

Top
#72452 - 2003-01-08 11:09 PM Re: Extract part of a string
Anonymous
Unregistered


Does it help any if I use the LEN command? I can make a variable out of the drive and directory (F:\AGG or F:\CMD Files). That way you could just count over that many characters and then extract from there.
Top
#72453 - 2003-01-08 11:13 PM Re: Extract part of a string
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Mike:

You will need to have some kind of structure in that string if you want to successfully parse it. However, as we do not know what variations you can have, I can't say whether LEN() would be good. The use of LEN() would assume that you do have part of the string in some other form. Your best bets are a combination of SUBSTR(), SPLIT() and INSTR()/INSTRREV() to separate the strings into their components. you will also have to take care of cases line spaces in usernames or filenames or foldernames.

If you would post a list of potential strings then we might be able to help you more.

[ 08. January 2003, 23:16: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#72454 - 2003-01-08 11:13 PM Re: Extract part of a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What would help is if you were to provide enough information and not change the rules.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#72455 - 2003-01-08 11:16 PM Re: Extract part of a string
Anonymous
Unregistered


I'm not changing the rules, I'm throwing out options and ideas.

code:
BREAK ON

$DIR=F:\

SHELL "CMD.EXE /E:1024 /C DIR $DIR *. /AD /B /N > $DIR\DIRS.TXT"
Open(2,"$DIR\DIRS.TXT",4)
WRITELINE (2,"999999999")
CLOSE(2)

$INDEX2 = 0
$COUNT2 = 0

$index = 0 ; This index is used to count directories
$count = 0 ; This count is used to determine how many directories have been changed

SHELL "CMD.EXE /E:1024 /C CACLS $DIR > $DIR\CACLS.TXT"

$DIRLOC = $DIR
Open(1,"$DIR\CACLS.TXT",4)
WRITELINE (1,"THEEND")
CLOSE(1)
Open(1,"$DIR\CACLS.TXT",2)
Open(2,"$DIR\DIRS.TXT",2)
GOTO READACL

:SUBS

; This section reads each line of DIRS.TXT file with the directory information in it.

$D = ReadLine(2)
; "$D"

; This secition will take the output file with the ACL information
; and wrote THEEND at the end of it to mark the end of the file

$DIRLOC='$DIR'+'$D'
? "$DIRLOC"


$shellstring2='cacls ' + '"$DIRLOC"'+ ' >' + ' "$DIRLOC' + '\CACLS.TXT"'
? "$SHELLSTRING2"
; SHELL "CMD.EXE /E:1024 /C CACLS $DIRLOC > $DIRLOC\CACLS.TXT"
shell '%COMSPEC% /e:1024 /c '+$shellstring2

Open(1,'$DIRLOC' + \CACLS.TXT,4)
WRITELINE (1,"THEEND")
CLOSE(1)
Open(1,$DIRLOC + \CACLS.TXT,2)


; This section reads each line of the CACLS.TXT file with the ACL information in it.
; If the line has D01\ in it, the program will extract the user name or group name
; associated with D01\ and make it the $NAMEGRP variable

:READACL

$X = ReadLine(1)
; ? "$X"
IF $X = "THEEND"
CLOSE(1)
$COUNT2 = $COUNT2 + 1
$INDEX2 = $INDEX2 + 1
Goto SUBS
Endif
IF $X = "999999999"
Goto Done
ENDIF


IF INSTR ("$X", "EVERYONE")
$Account = split(split($X,":")[0],"\")
$NAMEGRP = LTRIM($Account[0])
; ? "$NAMEGRP"
GOTO PERMISSION
ENDIF

IF INSTR ("$X", "D01\") <> 0
$Account = split(split($X,":")[0],"\")
$NAMEGRP = $Account[1]
; ? "$NAMEGRP"
GOTO PERMISSION
ELSE
GOTO COUNT
ENDIF


:PERMISSION
$P = SUBSTR($X, LEN(RTRIM($X)), 1)
; ? "$P"

IF $P='N' OR $P='R' OR $P='W' OR $P='C' OR $P='F'

; This section will take the $NAMEGRP variable and add an ACL for the same user or group
; in the BIO domain. Giving that user or group None, Read, Write, Change or Full Control.


; $shellstring='cacls ' + '$DIRLOC'+ ' /E /t /g' + ' BIO\' + '$NAMEGRP' + ':' + '$P'
$shellstring='cacls ' + '$DIRLOC'+ ' /E /g' + ' BIO\' + '$NAMEGRP' + ':' + '$P'
; shell '%COMSPEC% /e:1024 /c '+$shellstring
? "$shellstring"

ENDIF

:COUNT
$count = $count + 1 ;increase the count of directories
$index = $index + 1 ;increment index for next pass


goto READACL ;loop and read next ACL

CLOSE (1)
CLOSE (2)

:Done

? "Done!"
? ""


Top
#72456 - 2003-01-08 11:19 PM Re: Extract part of a string
Anonymous
Unregistered


And the potential values for $X will vary greatly. $X will be a drive letter and a folder name(s). Could be F:\ could be F:\My Documents or F:\My Music Files .....etc.
Top
#72457 - 2003-01-08 11:21 PM Re: Extract part of a string
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Would you mind explaining in simple words what exactly this script is supposed to do?
_________________________
There are two types of vessels, submarines and targets.

Top
#72458 - 2003-01-08 11:23 PM Re: Extract part of a string
Anonymous
Unregistered


If someone can tell me the script that would take a value like "F:\CMD Files DOMAIN\USERNAME:F" and let me count over the number of characters to cover the Drive and folder name:
code:
$S = LEN($DIRLOC + 1)
? "$S

Then extract from the \ after domain to the : before the permission. Thanks!

Top
#72459 - 2003-01-08 11:25 PM Re: Extract part of a string
Anonymous
Unregistered


The script does the directory of a given folder or drive and outputs all the directory names to a TXT file. Then it goes though each folder and outputs the ACL information to another TXT file. From that TXT file it scans each ACL entry for D01\ If it finds D01\ then it will add an ACL entry for the same user name only in the BIO domain.
Top
#72460 - 2003-01-08 11:35 PM Re: Extract part of a string
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If you need to retrieve a list of directories, then take a look at the DirPlus() or any other DIR() UDF and read DIR() Primer and File Operations in the FAQ Forum.

Then you can do this:
code:
$string='F:\CMD Files DOMAIN\USERNAME:F'
$dirloc=''F:\CMD Files'
$userperm=substr($string,len($dirloc)+2)
if instr($userperm,':')
$userperm=split($userperm,':')
$user=$userperm[0]
if instr($user,'\')
$user=split($user,'\')
$domain=$user[0]
$username=$user[1]
else
; error handler
endif
$perm=$userperm[1]
else
; error handler
endif

or something like this.
_________________________
There are two types of vessels, submarines and targets.

Top
#72461 - 2003-01-08 11:50 PM Re: Extract part of a string
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
MikeT, you doing this the hardest way possible.

Are you trying to migrate security on member servers or domain user accounts from one domain to another?

Please detail your business needs (not your code). I think I can give you direction to complete your task in minutes.

[ 08. January 2003, 23:51: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1183 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.08 seconds in which 0.037 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org