Page 1 of 1 1
Topic Options
#43103 - 2003-07-21 01:41 AM Selecting parsed variables
Anonymous
Unregistered


Hi guys. My first post and I'm not a developer or programmer so please don't be too harsh.

I am looking for a way to select a certain variable from a line read from a file. In REXX variables could be parsed (space delimited) using the function PARSE VAR as in the example below.

Say a line in a file was written as follows

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.

And I wanted to find out what the third word in the line was. I would write the REXX procedure as follows:

PARSE VAR [line read in] #var1 #var2 #var3 #var4

Which would give me an output of

THE
QUICK
BROWN
FOX JUMPED OVER THE LAZY DOG

Of more succinctly I would simply select the variable in my code as follows:

SAY #var3

Which would display on the screen "BROWN".

I would like to do the same thing with Kixtart and I have looked at SPLIT but this does not seem to allow me to achieve this, e.g. choose which variable I want to work on. Am I doing something wrong? Any help or direction would be most appreciated.

Sorry for the long-winded example....

Kenno

kjmoule@mmm.com

Top
#43104 - 2003-07-21 01:55 AM Re: Selecting parsed variables
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Welcome to the board. Split() should have done it for you. I did not provide an example of how to ReadLine() in the $Line but if you need, can do that too.

code:
break on
$Line = 'THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.'

$Words = Split($Line, ' ')

For each $Word in $Words
? $Word
Next

? $Words[2]

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#43105 - 2003-07-21 01:57 AM Re: Selecting parsed variables
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Hmmm... your first post you say?
http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=recent_user_posts;u=00002296
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#43106 - 2003-07-21 02:15 AM Re: Selecting parsed variables
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
A first post with a postcount of 5? [Confused]

Anyway, if your textfile indeed contains variables (e.g. $quick) and not words (e.g. quick), then you will also have to use the EXECUTE statement in order to tell Kixtart that you now want to deal with a variable. However, in general, it is a bad idea to dynamically generate varible names.

Please tell us your "big picture" with regards to this script.
_________________________
There are two types of vessels, submarines and targets.

Top
#43107 - 2003-07-21 02:38 AM Re: Selecting parsed variables
Anonymous
Unregistered


Hmmmm! 5 posts indeed (I checked). I really have to stop working so hard because I had completely forgotten about those other posts....

Anyway, thanks to both of you for the quick reply. In response to sealeopard's query here is the big picture and a snapshot of the code I am writing.....

code:
 BREAK ON

$RC = REDIRECTOUTPUT("",0)
"Gathering password age statistics. Please do not interrupt." ?

dim $servers[28]
$array_num = 0
call "c:\kixtart\server_list.scr"
$output = "C:\PWAGE.TXT"
$age_limit = 91
$readout = "C:\PWAGEFIL_THN.TXT"

$RC = REDIRECTOUTPUT($readout,1) ;\\Overwrite old file

;//Do local server accounts (listed in the array)
while $server[$array_num] <> 0
shell "cmd.exe /c c:\kixtart\netpwage.exe /USERS /COMPUTER:" + $server[$array_num] + " /MIN:" + $age_limit + " /B >" + $output

$RC = REDIRECTOUTPUT($readout,0)
"Local Account Password Age Listing for Server "$server[$array_num] ?
"------------------------------------------------------------------------------------------------" ?

$rc = open(1,$output,2)
$line = readline(1)
do
$line = readline(1)

;$string = len($line)
$accounts = SPLIT($line,,)
for each $account in $accounts
next
;$pwage = substr($line,($string - 3),4)


;$string = len($line)
;$accounts = substr($line,1,20)
;$pwage = substr($line,($string - 3),4)

select
case $accounts = "" $rc = close(1) goto no_accounts_to_list1
case $accounts = "Failed to retrieve u" $rc = close(1) goto errorlog1
endselect

$RC = REDIRECTOUTPUT($readout,0)
" Account Name: " + $accounts[0] + " Password Age:$pwage days Last logged on:14/5/2003 19:50" ?
until $line = ""

:no_accounts_to_list1
$RC = REDIRECTOUTPUT($readout,0)
" No more accounts exceed the " + ($age_limit - 1) + " day password age limit." ?
goto breakloop1

:errorlog1
$RC = REDIRECTOUTPUT($readout,0)
" Failed to retrieve account list from this server." ?

:breakloop1
$RC = REDIRECTOUTPUT($readout,0)
?

$array_num = $array_num + 1
loop
exit

The line I read in is as follows...

Administrator User Account 98

.... and I wish to display the account name and the password age (98) in an output. I am having a bit of difficulty with SPLIT so your help is most grateful.

Kenno

P.S Bear in mind that this is the code that I am playing around with so some syntax errors will be evident.

Top
#43108 - 2003-07-21 02:46 AM Re: Selecting parsed variables
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You're not really using the $server varibale, and you've hardcoded the number. It would be better to just read the text file line by line and , if necessary, redim the array with REDIM.

The split is actually very straighforward. Using
quote:
Administrator User Account 98
as an exmaple, SPLIT will result in a 4-element array with indices 0-3. Index 0 is "Administartor, index 3 is "98". You can address indices with the square brackets, e.g. $variable[0] for the first element.

BTW, you should not use GOTO in code as it is a very bad habit, so don't start it [Smile]
_________________________
There are two types of vessels, submarines and targets.

Top
#43109 - 2003-07-21 04:05 AM Re: Selecting parsed variables
Anonymous
Unregistered


Thanks again for the reply and advise re: GOTO. I hate using it myself as it is just a lazy way of getting around the code.

I need to go and tend to a few support calls but will let you know how I go with your suggestions etc.

Kenno

BTW sealeopard in my Navy (RAN) days submariners used to call us "skimmers" and we used to call submariners "sludgemariners", because of the lack of showers they were allowed to have

Kenno

Top
#43110 - 2003-07-21 04:48 AM Re: Selecting parsed variables
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Shower, what's that? [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
#43111 - 2003-07-21 05:16 AM Re: Selecting parsed variables
Anonymous
Unregistered


I believe "showers" are where you half fill a basin with water (preferrably the colder the better) then proceed to dip your right hand into the basin and splash water in an upward motion towards your left armpit, which you have stuck out at a 45 degree angle relative to the floor. This practice is then reversed until both armpits are wet.
Top
#43112 - 2003-07-21 08:04 AM Re: Selecting parsed variables
Anonymous
Unregistered


Hi all,
I have taken onboard all advice, suggestions and wisdom have learnt a bit more about Kixtart. I am still having problems with the SPLIT function although I think I know why and hence this new reply.

The output I obtain from the initial READLINE is as follows:

code:
Administrator             User Account        98

As you can see there is more than one space delimiter between "Administrator" and "User" as well as between "Account" and "98". This seems to affect SPLIT because if I put in an element of $array[3] I get nothing but if I put in the element of $array[22] I get the "98" result. Unfortunately this has other problems further on.

If I put in 6 spaces in the function, e.g.
code:
SPLIT($Line,"      ",)

this also works but again there is the same problem further on.

Again thanks for your help.
Kenno

Top
#43113 - 2003-07-21 08:14 AM Re: Selecting parsed variables
Anonymous
Unregistered


Hi all,
Further to my last message; I have found a 'workaround'. It's a bit scrappy but it will do for the moment unless you guys/gals come up with a better option. The workaround is instead of having

code:
$word[3]

to display the "98" result I have simply done this;

code:
$age = ubound($word)
$word[$age]

which obtains the results without any errors down the line.

Thanks again
Kenno

Top
#43114 - 2003-07-21 03:35 PM Re: Selecting parsed variables
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
code:
$a='Administrator             User Account        98'
while instr($a,' ')
$a=join(split($a,' '),' ')
loop

will remove all double spaces until only single spaces are left. BTW, you never mentioned that there were multiple spaces sued as the delimiter. Your examples all indicated single spaces only.
_________________________
There are two types of vessels, submarines and targets.

Top
#43115 - 2003-07-22 12:02 AM Re: Selecting parsed variables
Anonymous
Unregistered


Thanks for the code example sealeopard. I haven't tried it yet but I'm sure it will work. I have misinterpreted SPLIT as being able to delimit multiple spaces hence why I didn't specify that in my previous replies (I'm a REXX coder from way back and I have a tendency to think the same rules apply for Kixtart).

BTW you will be please to know I using GOSUB rather than GOTO in the code with the exception of one GOTO statement and that is used to break the loop. Is there any other command that can break out of a loop when required?

Thanks again
Kenno

Top
#43116 - 2003-07-22 02:52 AM Re: Selecting parsed variables
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Setting the correct exit conditions will break the loop
code:
do
; stuff
until $line=''

_________________________
There are two types of vessels, submarines and targets.

Top
#43117 - 2003-07-22 06:59 PM Re: Selecting parsed variables
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
To get back to the original objective... that being to get the password age, that can all be done using ADSI. No need for kludgy text file parsing.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#43118 - 2003-07-25 01:23 AM Re: Selecting parsed variables
Anonymous
Unregistered


Thanks for that info and your advice. I have actually plagiarised a script (using ADS) I found through this BB and it is doing the job perfectly.

Kenno

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1188 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.065 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

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