#43103 - 2003-07-21 01:41 AM
Selecting parsed variables
|
Anonymous
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
|
|
|
|
#43107 - 2003-07-21 02:38 AM
Re: Selecting parsed variables
|
Anonymous
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
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
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#43109 - 2003-07-21 04:05 AM
Re: Selecting parsed variables
|
Anonymous
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
|
|
|
|
#43111 - 2003-07-21 05:16 AM
Re: Selecting parsed variables
|
Anonymous
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
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
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
|
|
|
|
#43115 - 2003-07-22 12:02 AM
Re: Selecting parsed variables
|
Anonymous
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
|
|
|
|
#43118 - 2003-07-25 01:23 AM
Re: Selecting parsed variables
|
Anonymous
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1188 anonymous users online.
|
|
|