At 09:43 AM 4/14/00 +0200, you wrote:
>Hi,
>Uhm.. yeah, but where's the attachment? =)
>
>//Best Regards
>Stefan Falk
>
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
>> Sent: Thursday, April 13, 2000 5:55 PM
>> To: [EMAIL PROTECTED]
>> Subject: [REBOL] Removing lines... Re:
>>
>> Hi Stefan:
>> I have attached a file called "remove.r". It has
>> two functions that were provided to me by other members
>> of the mailing list. Perhaps there are others that
>> would find it useful. The first one is the one that I
>> was looking for. It will replace text between two markers,
>> so that it has the effect of rewriting a record in a simple
>> database.
>> I hope you find this helpful.
>> Regards
>> Tim
>> At 10:55 AM 4/13/00 +0200, you wrote:
>> >Hi list,
>> >I've read a textfile with read/lines....is there an easy way to remove a
>> >line from the data?
>> >
>> >it goes something like:
>> >
>> >data: read/lines %blaah.txt
>> >
>> >if find data "plupp" [remove the line] <--- of course there oughta be
>> some
>> >easy code there.. ;)
>> >
>> >Best Regards
>> >Stefan Falk
>> >
>> >
>
>
REBOL
[
Title: "Test File Insertion"
Date: 9-Feb-2000
Author: "Tim Johnson via Ladislav and others"
Email: [EMAIL PROTECTED]
File: %Remove.r
Purpose:{To test removing text from a block}
]
remove-text: func
[fp1[file!] ins_series[series!] begin_marker[string!] end_marker[string!]]
[
;insert_txt: ["first new line" "second new line" "third new line"]
fp: open/lines fp1
remove_flag: false
lines-done: 0
while[not tail? fp] ;test for end of block
[
if find first fp begin_marker ;"begin insert here"
[remove_flag: true] ;prepare to insert but pointer must move to next
either remove_flag ;we will now remove nodes from fp
[
either find first fp end_marker ;"end insert here" ; check for end marker
[
remove_flag: false ; turn flag off
foreach txt ins_series ; insert the new series
[fp: insert fp txt]
fp: next fp ; and proceed read/write
]
[ {else}
either zero? lines-done ; begin insertion
[
lines-done: 1
fp: next fp
]
[{else} remove fp]
]
]
[{else} fp: next fp]
]
update fp
close fp
]
insert_txt: ["first new line" "second new line" "third new line"]
begin_marker: "begin insert here"
end_marker: "end insert here"
nfile: "test.txt"
file_name: make file! nfile
print file_name
remove-text file_name insert_txt begin_marker end_marker
;file begins here
;<!--begin insert here-->
;original line one
;original line two
;original line three
;<!--end insert here-->
;file ends here
replace-text: func [
fp [file!] "text file with lines to be updated"
rp [file!] "text file holding lines to be inserted"
][
fp: open/lines fp
rp: read/lines rp
lines_removed: 0
lines_inserted: 0
while [ not tail? fp ] [
if find first fp "begin replace here" [
print "found"
fp: next fp
lines_inserted: lines_inserted + length? rp
fp: insert fp rp
while [all [
not tail? fp
not find first fp "end replace here"
]][
lines_removed: lines_removed + 1
remove fp
]
break
]
fp: next fp
]
print [lines_removed "lines removed"]
print [lines_inserted "lines inserted"]
update fp
close fp
]