How to resolve the algorithm Remove lines from a file step by step in the TUSCRIPT programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Remove lines from a file step by step in the TUSCRIPT programming language
Table of Contents
Problem Statement
Remove a specific line or a number of lines from a file. This should be implemented as a routine that takes three parameters (filename, starting line, and the number of lines to be removed). For the purpose of this task, line numbers and the number of lines start at one, so to remove the first two lines from the file foobar.txt, the parameters should be: foobar.txt, 1, 2 Empty lines are considered and should still be counted, and if the specified line is empty, it should still be removed. An appropriate message should appear if an attempt is made to remove lines beyond the end of the file.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Remove lines from a file step by step in the TUSCRIPT programming language
Source code in the tuscript programming language
$$! input=testfile,begnr=3,endnr=4
$$ MODE TUSCRIPT
- CREATE inputfile
ERROR/STOP CREATE (input,FDF-o,-std-)
FILE/ERASE $input
LOOP n=1,9
content=CONCAT ("line",n)
DATA {content}
ENDLOOP
ENDFILE
- CREATE outputfile
output="outputfile"
ERROR/STOP CREATE (output,fdf-o,-std-)
ACCESS q: READ/RECORDS/utf8 $input L,line
ACCESS z: WRITE/RECORDS/utf8 $output L,line
PRINT "content: of output-file"
LOOP/9999
READ/NEXT/EXIT q
IF (begnr<=L&&endnr>=L) CYCLE
PRINT line
WRITE z
ENDLOOP
ENDACCESS/PRINT q
ENDACCESS/PRINT z
You may also check:How to resolve the algorithm Doomsday rule step by step in the Julia programming language
You may also check:How to resolve the algorithm Church numerals step by step in the Octave programming language
You may also check:How to resolve the algorithm Maze solving step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Stack step by step in the BASIC programming language
You may also check:How to resolve the algorithm Terminal control/Clear the screen step by step in the Axe programming language