There was a case when I needed to delete lines from text file that contains a say "foo" as an example.
This is what I did. use readline to read the lines, check, and if the line contains "foo" skip, else write the line to a temporary file. At the line, use Rename to rename the temporary file to the file being read.
dir_name:="C:/tmp"; currentdir(dir_name); tmp_file_name := "TMP.txt"; source_file_name := "source.txt"; file_id := fopen(tmp_file_name,WRITE): line := readline(source_file_name): while line<>0 do if not StringTools:-Has(line,"foo") then fprintf(file_id,"%s\n",line); fi; line := readline(source_file_name): od: fclose(file_id); FileTools:-Rename(tmp_file_name,source_file_name,force=true);