Read a specific line from a file: Difference between revisions

m
→‎{{header|REXX}}: changed some comments, added whitespace. -- ~~~~
(Added BBC BASIC)
m (→‎{{header|REXX}}: changed some comments, added whitespace. -- ~~~~)
Line 681:
=={{header|REXX}}==
<lang REXX>/*REXX program to read a specific line from a file. */
 
parse arg fileId n . /*get the user args: fileid n */
if fileID=='' then fileId='JUNK.TXT' /*assume the default: JUNK.TXT */
if n=='' then n=7 /*assume the default (n=7) */
L=lines(fileid) /*first, see if the file exists. */
if L ==0 then do; say 'error, fileID not found:' fileId; exit; end
if n\==1 then call linein fileId,n-1 /*second, read previous rec. to N*/
 
if n\==1 then call linein fileId,n-1 /*second, read previous rec. to N*/
L=lines(fileid) /* L = # lines left in the file.*/
q=linein(fileId,n) /*read the Nth line, store in Q.*/
qL=length(q) /*get the length of the record. */
 
select
when L==0 & qL==0 then say 'line' n "not found."
when L==10 & qL==0 then say 'line' n "has a zeronot lengthfound."
when L==1 & qL==0 otherwise then say 'fileline' fileIdn "record"has na '='zero qlength."
otherwise end /*select*/ say 'file' fileId "record" n '=' q
end /*select*/
exit /*stick a fork in it, we're done.*/
/*┌────────────────────────────────────────────────────────────────────┐
│ ─── Normally, we could just use: ─── │