Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Line reduction

From: aroberts:swri at: 5-Jul-2001 9:15

I have written the following program to remove any arbitrary number of lines from a file. It asks for an input file, output file, and the number of lines to skip before deleting. If you enter a 1, it will delete every other line. A 2 every third line. Etc. The input file is a text data set, representing numbers. Some files are quite large (2.5 Meg or more) Originally I tried writing it using a 'foreach/all/etc' call, but I couldn't get it to work. 1. How could I have written this using a different method? 2. What would be the fastest way of accomplishing this? (Since the input is all text based, would it be best to read in the values and convert them from string to numbers before doing the deletions?) Example data from a file: 1.093027 1.505329 0.826303 1.451725 1.226740 0.827948 1.698870 0.956003 0.829593 1.691551 0.693989 0.831238 1.792217 0.430279 0.832883 1.892038 0.167986 0.834528 1.919743 -0.092959 0.836173 -- Thank you, Aaron Roberts Southwest Research Institute Advanced Simulation Technologies Section (210)-522-5137 REBOL [ TITLE: "Remove lines" DATE: 3-July-01 ] input_file: ask "Enter the source file name: " output_file: ask "Enter the output file name: " skip_amount: ask "Remove lines every X line: " datafile: read/lines to-file input_file forskip datafile to-integer skip_amount[ remove datafile ] datafile: head datafile write/lines to-file output_file datafile