Well, to what purpose, and in which environment ?
If I understand it correctly, You want to store the file 'lines' in reversed order ?
And the system is VMS (otherwise post in a different forum :-).
The simplest, without intermediate files, is:
Read the file line-by-line, store lines in an array of strings, then write the output file looping over the array in reversed index order.
This way is only limited by the available memory in Your process.Second way:
read the file line-by-line, write intermediate file with line numbers preceding the text; use SORT/key=(pos:1,size:n,descending)
Then read the sorted intermediate file again, remove the line numbers.
Without writing Your own program, use the a TPU editor procedure
( http://wwwvms.mppmu.mpg.de/vmssig/src/tpu/EVE_LINE_NUMBERS.TPU
).
This makes 2 editor commands: NUMBER and UNNUMBER.
So the sequence is:
$ EDIT/TPU/Command=EVE_LINE_NUMBERS.TPU
command NUMBER
command WRITE TEMP.TXT
command SPAWN SORT ... ! the above sort command
command READ output of sort command
command UNNUMBER
Now we have the text file in reversed line number.
You can of course do all entirely in DCL:
$ open/read in myfile
$ open/write out numbered_file
$n=1
$loop:
$read/end=done in line
$ write out f$fao("!6UL",n),line
$goto loop
$done:
$close in
$close out
$ sort numbered_file reversed_file /key=(pos:1,siz:6,descending)
$ open/read in reversed_file
$ open/write reversed_text
$loop2:
$ read/end=done2 in line
$ write out f$extract(7,f$length(line)-7,line)
$ goto loop2
$done2:
$ close in
$ close out