Page 1 of 2 12>
Topic Options
#73780 - 2003-02-28 02:37 PM determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Hi everyone,
i'm currently suffering a bit from writersblock while writing a kixfile that
should read consecutively each line from a plain txt file, strip the last character
away and dump the info into a resulting text file.

I've got the stripping and output sequence ready but i'm a bit lost as to figure
out how many lines there are in the input text file. If i can determine that i can
do an open file + a readline and retrieve each line that way.
Can someone clarify this for me??

Here's the bit of code i already got.

$text="blablabla$"
open(1,"f:\temp\test\dirs\result.txt",5)
WriteLine( 1 , left($text,LEN($text) - 1) + @CRLF)

As soon as i figure out how many lines there are in the text file i can replace the
"blablabla" string by the readline instruction.

The ultimate purpose is to retrieve a dir /b from all dirs in a certain directory
and compare that info with the existing shares on a certain server.
This is to check wether someone accidentally deleted a directory without removing the
share first ( we are running a fileserver on a W2K cluster and this might cause serious
problems when someone deletes a dir before removing the share. The parent
resource can fail and cause a lot of interuptions.

Alternatively i could pull it off by calling the kix script from a batch routine and feeding it with
an external variable like this. Sad thing is that i can't immediately find how to tell the script
to accept this external parameter.

for /f %%i in ('type f:\temp\test\dirs\input.txt') do f:\temp\test\dirs\kix32 f:\temp\test\dirs\find.kix "parameter"

[ 28. February 2003, 14:43: Message edited by: RobinHood ]

Top
#73781 - 2003-02-28 02:58 PM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
For those who might need it in the future here's how to ( figured it out just now ).

The kix script strippit.kix contains the following

open(1,"f:\temp\test\dirs\result.txt",5)
WriteLine( 1 , left($text,LEN($text) - 1) + @CRLF)

The batch file does this

for /f %%i in ('type f:\temp\test\dirs\input.txt') do f:\temp\test\dirs\kix32 f:\temp\test\dirs\strippit.kix $text=%%i

Next challenge for me right now is to hunt support.microsoft.com and figure out
how i can retrieve all underlying shares under a cluster fileshare resource.

Once i'll have it i'll dump the code in here for those who are interested.

Top
#73782 - 2003-02-28 02:59 PM Re: determining how many lines there are in a plain txt file
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I don't know if you need to know the actual number of lines. I think might want something like this.

code:
  
open(1,"f:\temp\test\dirs\result.txt",5)
open(2, "f:\temp\test\dirs\source.txt")
$line = readline(2)
while @ERROR = 0
WriteLine( 1 , left($line,LEN($line) - 1) + @CRLF)
$line = readline(2)
loop
close(1)
close(2)

_________________________
Eric

Top
#73783 - 2003-02-28 03:03 PM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Thanks,
tried it and it's even faster then my routine.

Edwin

[ 28. February 2003, 15:10: Message edited by: RobinHood ]

Top
#73784 - 2003-02-28 04:59 PM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Yes,
it's me again. I've got it almost figured out so here's already a bit of the code.

open(1,"f:\temp\test\properset\strip-shares.txt",5)
open(2, "f:\temp\test\properset\detect.txt")
$line = readline(2)
while @ERROR = 0
$MyArray = split($line,"$")
WriteLine( 1 , $myarray[0] + @CRLF)
$line = readline(2)
loop
close(1)
close(2)

The reason why i am using an array in there is that the sourcefile contains an input similar to this one

' '
'Share name Resource Remark'
' '
'-------------------------------------------------------------------------------'
user$ z:\path\user text
'The command completed successfully.'

As a result i'll get

' '
'Share name Resource Remark'
' '
'-------------------------------------------------------------------------------'
user
'The command completed successfully.'

Note that the stuff in bold is some left over garbage which i would like to delete.
Since it's friday evening over here i'm a bit tired and am again suffering from writers block.
If anyone knows a genious trick of kicking out those garbage lines from my result file
i would appreciate it. So the lines i want to get rid off are always lines 1-4 and the last line.

Thanks to all who 've helped me untill now.

Top
#73785 - 2003-02-28 05:01 PM Re: determining how many lines there are in a plain txt file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Looks like you're printing @SERROR lines.
_________________________
There are two types of vessels, submarines and targets.

Top
#73786 - 2003-02-28 05:13 PM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Jens,
i'm using a a chm manual from Kix as reference so although i may not know it right now,
and it's friday, i might have figured it out next monday.
I'm taking my scripts & the kix executable home and will play a bit with it over the weekend.
Although the manual is very complete i haven't found the proper solution for my problem yet.

What are these UDF's exactly?? I'm still used to Kix 3.6x and have only recently made the jump
to 4.20 so it's a bit overwhelming.

He, you can't blame an inexperienced scriptwriter for having a bit of writers block from time to time and i do love the forum in here.

[ 28. February 2003, 17:15: Message edited by: RobinHood ]

Top
#73787 - 2003-03-01 04:26 PM Re: determining how many lines there are in a plain txt file
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Write only the lines that you want to. Maybe something like this:

code:
  
open(1,"f:\temp\test\dirs\result.txt",5)
open(2, "f:\temp\test\dirs\source.txt")
$line = readline(2)
while @ERROR = 0
if instr($line, "$")
WriteLine(1, split($line, "$")[0] + @CRLF)
endif
$line = readline(2)
loop
close(1)
close(2)

_________________________
Eric

Top
#73788 - 2003-03-01 04:57 PM Re: determining how many lines there are in a plain txt file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Please take a look at the FAQ Forum, especially How to use UDFs .

Also, take a look at the printed Manual that comes with the KiXtart ZIP file.

[ 01. March 2003, 16:59: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#73789 - 2003-03-03 10:24 AM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Damn,
those UDF's seem to be a powerful thing i haven't considered yet. I hope there's a good
walkthru in the kix help files. Must have a good look at this ....

Top
#73790 - 2003-03-03 02:07 PM Re: determining how many lines there are in a plain txt file
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
RobinHood,

Did you get a chance to peruse my recent post that is asking a similar question?

Script for adding in a new ePolicy Orchestrator server

Essentially, this looks at an INI file for a string using READLINE and if it does not exist, it makes changes using WRITELINE, closes the file and then uses WRITEPROFILESTRING to make additional changes.

This should get you pointed in the right direction.

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#73791 - 2003-03-03 03:27 PM Re: determining how many lines there are in a plain txt file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
See also GetLineCount() - Counts the lines in a given text file in the ScriptLogic UDF Library.
_________________________
There are two types of vessels, submarines and targets.

Top
#73792 - 2003-03-04 09:51 AM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Kent,
thanks for the info but i hadn't noticed your topic yet. I'll have a look and print of the
code so i can check it out ( might learn something valuable from it ).

Jens,
i 've checked out those UDF's and found some interesting ones. I might even consider
digging in deeper into the UDF's in the near future but i solved the problem using a couple
of basic if then's and a select - case - endselect.

I'm going to double check the code once more and i'll post it in here.
I'll try to use different colors like in Kent's example but forgive me if i might
forget it. Remember that the code may not resemble what you would have made of it
because i 'm not as good as some of the kix fans in here.

Thanks to all,
Edwin

Top
#73793 - 2003-03-04 02:04 PM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Does anyone have an alternative url of the GetLineCount() UDF?? The link specified above
times out each try.

I had a problem with the while @error = 0 in such a way that the 2nd loop in the script wouldn't execute. Figured out that it was releated to the open(file) & close(file) commands.

[ 04. March 2003, 14:24: Message edited by: RobinHood ]

Top
#73794 - 2003-03-04 02:34 PM Re: determining how many lines there are in a plain txt file
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
RobinHood,

Made a change to your code -
code:
CLS
BREAK ON
open(1,"c:\CONFIG.NT")
open(2,"c:\WINDOWS\SYSTEM32\CONFIG.NT")

$mxcount1 = 0
$mxcount2 = 0
$stripp = readline(1)
WHILE @error = 0
$buildmx1array = $stripp
$stripp = readline(1)
$mxcount1 = $mxcount1 + 1
LOOP

$check = readline(2)
WHILE @error = 0
$buildmx2array = $check
$check = readline(2)
$mxcount2 = $mxcount2 + 1
LOOP

? "file 1 contains " + $mxcount1 + " lines, and file 2 contains " + $mxcount2 + " lines"
FOR $count1 = 1 TO $mxcount1 STEP 1
FOR $count2 = 1 TO $mxcount2 STEP 1
? "comparing line " + $count1 + " from file 1 with line " + $count2 + " from file 2"
NEXT
NEXT

$rc=close(1)
$rc=close(2)
? "Max Counter 1 = " + $mxcount1 + @crlf
? "Max Counter 2 = " + $mxcount2 + @crlf
get $c

Results are -
quote:

comparing line 47 from file 1 with line 1 from file 2
comparing line 47 from file 1 with line 2 from file 2
comparing line 47 from file 1 with line 3 from file 2
comparing line 47 from file 1 with line 4 from file 2
comparing line 47 from file 1 with line 5 from file 2
comparing line 47 from file 1 with line 6 from file 2
comparing line 47 from file 1 with line 7 from file 2
comparing line 47 from file 1 with line 8 from file 2
comparing line 47 from file 1 with line 9 from file 2
comparing line 47 from file 1 with line 10 from file 2
comparing line 47 from file 1 with line 11 from file 2
comparing line 47 from file 1 with line 12 from file 2
comparing line 47 from file 1 with line 13 from file 2
comparing line 47 from file 1 with line 14 from file 2
comparing line 47 from file 1 with line 15 from file 2
comparing line 47 from file 1 with line 16 from file 2
comparing line 47 from file 1 with line 17 from file 2
comparing line 47 from file 1 with line 18 from file 2
comparing line 47 from file 1 with line 19 from file 2
comparing line 47 from file 1 with line 20 from file 2
comparing line 47 from file 1 with line 21 from file 2
comparing line 47 from file 1 with line 22 from file 2
comparing line 47 from file 1 with line 23 from file 2
comparing line 47 from file 1 with line 24 from file 2
comparing line 47 from file 1 with line 25 from file 2
comparing line 47 from file 1 with line 26 from file 2
comparing line 47 from file 1 with line 27 from file 2
comparing line 47 from file 1 with line 28 from file 2
comparing line 47 from file 1 with line 29 from file 2
comparing line 47 from file 1 with line 30 from file 2
comparing line 47 from file 1 with line 31 from file 2
comparing line 47 from file 1 with line 32 from file 2
comparing line 47 from file 1 with line 33 from file 2
comparing line 47 from file 1 with line 34 from file 2
comparing line 47 from file 1 with line 35 from file 2
comparing line 47 from file 1 with line 36 from file 2
comparing line 47 from file 1 with line 37 from file 2
comparing line 47 from file 1 with line 38 from file 2
comparing line 47 from file 1 with line 39 from file 2
comparing line 47 from file 1 with line 40 from file 2
comparing line 47 from file 1 with line 41 from file 2
comparing line 47 from file 1 with line 42 from file 2
comparing line 47 from file 1 with line 43 from file 2
comparing line 47 from file 1 with line 44 from file 2
comparing line 47 from file 1 with line 45 from file 2
comparing line 47 from file 1 with line 46 from file 2
comparing line 47 from file 1 with line 47 from file 2
comparing line 47 from file 1 with line 48 from file 2
comparing line 47 from file 1 with line 49 from file 2
comparing line 47 from file 1 with line 50 from file 2
comparing line 47 from file 1 with line 51 from file 2
comparing line 47 from file 1 with line 52 from file 2
comparing line 47 from file 1 with line 53 from file 2
comparing line 47 from file 1 with line 54 from file 2
comparing line 47 from file 1 with line 55 from file 2
comparing line 47 from file 1 with line 56 from file 2
comparing line 47 from file 1 with line 57 from file 2
comparing line 48 from file 1 with line 1 from file 2
comparing line 48 from file 1 with line 2 from file 2
comparing line 48 from file 1 with line 3 from file 2
comparing line 48 from file 1 with line 4 from file 2
comparing line 48 from file 1 with line 5 from file 2
comparing line 48 from file 1 with line 6 from file 2
comparing line 48 from file 1 with line 7 from file 2
comparing line 48 from file 1 with line 8 from file 2
comparing line 48 from file 1 with line 9 from file 2
comparing line 48 from file 1 with line 10 from file 2
comparing line 48 from file 1 with line 11 from file 2
comparing line 48 from file 1 with line 12 from file 2
comparing line 48 from file 1 with line 13 from file 2
comparing line 48 from file 1 with line 14 from file 2
comparing line 48 from file 1 with line 15 from file 2
comparing line 48 from file 1 with line 16 from file 2
comparing line 48 from file 1 with line 17 from file 2
comparing line 48 from file 1 with line 18 from file 2
comparing line 48 from file 1 with line 19 from file 2
comparing line 48 from file 1 with line 20 from file 2
comparing line 48 from file 1 with line 21 from file 2
comparing line 48 from file 1 with line 22 from file 2
comparing line 48 from file 1 with line 23 from file 2
comparing line 48 from file 1 with line 24 from file 2
comparing line 48 from file 1 with line 25 from file 2
comparing line 48 from file 1 with line 26 from file 2
comparing line 48 from file 1 with line 27 from file 2
comparing line 48 from file 1 with line 28 from file 2
comparing line 48 from file 1 with line 29 from file 2
comparing line 48 from file 1 with line 30 from file 2
comparing line 48 from file 1 with line 31 from file 2
comparing line 48 from file 1 with line 32 from file 2
comparing line 48 from file 1 with line 33 from file 2
comparing line 48 from file 1 with line 34 from file 2
comparing line 48 from file 1 with line 35 from file 2
comparing line 48 from file 1 with line 36 from file 2
comparing line 48 from file 1 with line 37 from file 2
comparing line 48 from file 1 with line 38 from file 2
comparing line 48 from file 1 with line 39 from file 2
comparing line 48 from file 1 with line 40 from file 2
comparing line 48 from file 1 with line 41 from file 2
comparing line 48 from file 1 with line 42 from file 2
comparing line 48 from file 1 with line 43 from file 2
comparing line 48 from file 1 with line 44 from file 2
comparing line 48 from file 1 with line 45 from file 2
comparing line 48 from file 1 with line 46 from file 2
comparing line 48 from file 1 with line 47 from file 2
comparing line 48 from file 1 with line 48 from file 2
comparing line 48 from file 1 with line 49 from file 2
comparing line 48 from file 1 with line 50 from file 2
comparing line 48 from file 1 with line 51 from file 2
comparing line 48 from file 1 with line 52 from file 2
comparing line 48 from file 1 with line 53 from file 2
comparing line 48 from file 1 with line 54 from file 2
comparing line 48 from file 1 with line 55 from file 2
comparing line 48 from file 1 with line 56 from file 2
comparing line 48 from file 1 with line 57 from file 2
comparing line 49 from file 1 with line 1 from file 2
comparing line 49 from file 1 with line 2 from file 2
comparing line 49 from file 1 with line 3 from file 2
comparing line 49 from file 1 with line 4 from file 2
comparing line 49 from file 1 with line 5 from file 2
comparing line 49 from file 1 with line 6 from file 2
comparing line 49 from file 1 with line 7 from file 2
comparing line 49 from file 1 with line 8 from file 2
comparing line 49 from file 1 with line 9 from file 2
comparing line 49 from file 1 with line 10 from file 2
comparing line 49 from file 1 with line 11 from file 2
comparing line 49 from file 1 with line 12 from file 2
comparing line 49 from file 1 with line 13 from file 2
comparing line 49 from file 1 with line 14 from file 2
comparing line 49 from file 1 with line 15 from file 2
comparing line 49 from file 1 with line 16 from file 2
comparing line 49 from file 1 with line 17 from file 2
comparing line 49 from file 1 with line 18 from file 2
comparing line 49 from file 1 with line 19 from file 2
comparing line 49 from file 1 with line 20 from file 2
comparing line 49 from file 1 with line 21 from file 2
comparing line 49 from file 1 with line 22 from file 2
comparing line 49 from file 1 with line 23 from file 2
comparing line 49 from file 1 with line 24 from file 2
comparing line 49 from file 1 with line 25 from file 2
comparing line 49 from file 1 with line 26 from file 2
comparing line 49 from file 1 with line 27 from file 2
comparing line 49 from file 1 with line 28 from file 2
comparing line 49 from file 1 with line 29 from file 2
comparing line 49 from file 1 with line 30 from file 2
comparing line 49 from file 1 with line 31 from file 2
comparing line 49 from file 1 with line 32 from file 2
comparing line 49 from file 1 with line 33 from file 2
comparing line 49 from file 1 with line 34 from file 2
comparing line 49 from file 1 with line 35 from file 2
comparing line 49 from file 1 with line 36 from file 2
comparing line 49 from file 1 with line 37 from file 2
comparing line 49 from file 1 with line 38 from file 2
comparing line 49 from file 1 with line 39 from file 2
comparing line 49 from file 1 with line 40 from file 2
comparing line 49 from file 1 with line 41 from file 2
comparing line 49 from file 1 with line 42 from file 2
comparing line 49 from file 1 with line 43 from file 2
comparing line 49 from file 1 with line 44 from file 2
comparing line 49 from file 1 with line 45 from file 2
comparing line 49 from file 1 with line 46 from file 2
comparing line 49 from file 1 with line 47 from file 2
comparing line 49 from file 1 with line 48 from file 2
comparing line 49 from file 1 with line 49 from file 2
comparing line 49 from file 1 with line 50 from file 2
comparing line 49 from file 1 with line 51 from file 2
comparing line 49 from file 1 with line 52 from file 2
comparing line 49 from file 1 with line 53 from file 2
comparing line 49 from file 1 with line 54 from file 2
comparing line 49 from file 1 with line 55 from file 2
comparing line 49 from file 1 with line 56 from file 2
comparing line 49 from file 1 with line 57 from file 200
Max Counter 1 = 49

Max Counter 2 = 57

While this may not be the complete solution, we are getting a comparison..

HTH,

Kent

[ 04. March 2003, 14:46: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#73795 - 2003-03-04 02:41 PM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Mmm,
thanks. What i did was to open the file only before it's corresponding loop and to close it directly after the corresponding loop. That worked too.

Your example seens better because it allows me to declare everything at the top of my code.
I'll review and addapt my code.

Edwin

Top
#73796 - 2003-03-04 02:45 PM Re: determining how many lines there are in a plain txt file
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Edwin,

One more comment. [Smile]

If you want to suppress the 00, you will want to do the following:

$rc=close(1)
$rc=close(2)

HTH,

Kent

[ 04. March 2003, 14:45: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#73797 - 2003-03-04 02:53 PM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Kent,
thanks but let's leave the cosmetics untill i have adapted & cleaned up the script.
I think everyone in here would go crazy when they see all the spots where i've declared
variables ( with your code i can declare everything at the beginning of the script ).

Edwin

Top
#73798 - 2003-03-04 03:31 PM Re: determining how many lines there are in a plain txt file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Might be time to take a look at the FAQ Forum, e.g. Suppressing Results when running scripts and Why does the console display zeros and ones (amongst others)?
_________________________
There are two types of vessels, submarines and targets.

Top
#73799 - 2003-03-04 03:35 PM Re: determining how many lines there are in a plain txt file
RobinHood Offline
Fresh Scripter

Registered: 2001-10-11
Posts: 29
Jens,
i fully agree but as i said above, let's leave the cosmetics for the very end. I'll be already happy
when the damn thing continues to run after the changes i'm making right now.

Edwin

Top
Page 1 of 2 12>


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

Who's Online
1 registered (Bryce) and 183 anonymous users online.
Newest Members
gkustra, emnipetro, Hirze, thequeen, ameliaryan
17642 Registered Users

Generated in 0.041 seconds in which 0.01 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