Page 1 of 1 1
Topic Options
#25325 - 2002-07-18 03:09 AM Reading a File and Filter the outout to another file
Thinker Offline
Fresh Scripter

Registered: 2002-05-21
Posts: 10
Dear all,

I need to use kixtart to write a script to do the following urgently. Please help. Would very much appreciate any advise. Thanks in advance.

a. Read in a text file (eg. a.txt)
b. Check the line contents of file "a.txt".
c. If the 3rd column of the line contains certain keywords like "Yes".
d. Send the output to another text file.(eg. b.txt)
e. Run this recursively until all lines in the file is read.

Eg. a.txt

Col1 Col2 Col3 Col4
==== ==== ==== ====
David Male Yes Done
Mary Female No Done

Eg. b.txt

Col1 Col2 Col3 Col4
==== ==== ==== ====
David Male Yes Done
(Note line Mary was gone)

Top
#25326 - 2002-07-18 03:32 AM Re: Reading a File and Filter the outout to another file
t_pickering Offline
Fresh Scripter

Registered: 2001-11-23
Posts: 26
Hi Thinker,

Try this:-

code:
$input_filename = "input.txt"
$output_filename = "output.txt"

IF OPEN(1, $input_filename, 2) <> 0
? $input_filename + " is missing"
EXIT
ENDIF

IF OPEN(2, $output_filename,5) <> 0
? " Cannot open/create" + $output_filename
EXIT
ENDIF

DO
$line = READLINE(1)
IF INSTR($line, "Yes")
$result = WRITELINE(2, $line + CHR(13) + CHR(10))
? "Added " + $line + " to " + $output_filename
ENDIF
UNTIL @ERROR = -1

$result = CLOSE(1)
$result = CLOSE(2)

It's very quick and dirty ... but it does the job [Cool]

Top
#25327 - 2002-07-18 03:43 AM Re: Reading a File and Filter the outout to another file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
code:
break on cls
IF Open(1,"c:\a.txt") = 0
IF Open(2,"c:\b.txt",5) = 0
$x = ReadLine(1)
WHILE @ERROR = 0
? "Line read: [" + $x + "]"
If InStr($x,"yes")
$RC = WriteLine(2,$x + @CRLF)
? "Line written: [" + $x + "]"
ENDIF
$x = ReadLine(1)
LOOP
ENDIF
ENDIF

Get $_

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

Top
#25328 - 2002-07-18 09:07 AM Re: Reading a File and Filter the outout to another file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
Welcome back LES...

How's it been going? Hope things are well.

Top
#25329 - 2002-07-18 04:35 PM Re: Reading a File and Filter the outout to another file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Thanks DOC. Things are going well, what can I say... Did you get my email re: AD? Secret stuff... YES or NO answer only pls. Would like to continue that topic off-line.

I'm going to be real busy the next few months, so my posting rate will likely slide.

Lonkero will surpass me in no time. I see he is shameless when it come to the volume of totally useless posts... and I thought I was bad! Figure when he makes MM, I congratulate him for just one M.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25330 - 2002-07-18 08:43 PM Re: Reading a File and Filter the outout to another file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
Yes got email and I replied
Top
#25331 - 2002-07-21 11:51 AM Re: Reading a File and Filter the outout to another file
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear Les,

Welcome back. The biggest impact on the board are the Golf Tournament. It creates f.e. topics with the
greatest amount of replies.
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

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 584 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.143 seconds in which 0.114 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