#25325 - 2002-07-18 03:09 AM
Reading a File and Filter the outout to another file
|
Thinker
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
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
|
|
Top
|
|
|
|
#25331 - 2002-07-21 11:51 AM
Re: Reading a File and Filter the outout to another file
|
MCA
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.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 661 anonymous users online.
|
|
|