Talk:Reverse the order of lines in a text file while preserving the contents of each line

I can take no more

I've added a reference which I hope brings all this to an end!--Nigel Galloway (talk) 14:54, 4 August 2021 (UTC)

Incredibly vague task

Once again, the master of vagarity has struck. Some details need to be hammered out for this to be a task.

  • What is a line?
    • Is it a record that ends with a 0xD character?
    • a 0xA character?
    • a 0xA 0xD digraph?
    • Is there a particular encoding that can be assumed? (ASCII?, EBCDIC?, ISO-Latin-1?, UTF8?)
    • How about binary files?
  • What is to be reversed?
    • Each record in the file?
    • The order of records in a file?
    • Both?
    • What about binary files?
  • What restrictions are there on holding the file in memory?
    • Can it be read in all at once?
    • Does it need to be processed a record at a time?
    • Does it need to be read in starting from the end of the file, proceeding to the beginning?
      • If so, should it be processed in non-record sized blocks?
      • Or a byte / character at a time? (Which circles back around to encoding.)

Every single one of these questions will change the way the program must be written. --Thundergnat (talk) 14:34, 3 August 2021 (UTC)


I'll attempt to clarify at least one of your points.   It appears, from the   Ring   computer programming langage example,   that what is meant is to show the lines/records in reverse order,   and not change the order of the characters within each line (record).   I will also add a very small "file"   (to the task's preamble)   so that we can compare output(s) without having to show the input lines(records).     -- Gerard Schildberger (talk) 15:16, 3 August 2021 (UTC)

line/record termination

This might not be the proper forum or time to address the issue of line/record termination,   but not all operating systems terminate a line (or record) with any specific character (or characters).   That information may be contained in a meta structure,   which (may) contain the block length, record length, and type of blocking (if there is blocking), among other information.   It is (or can be) the purpose of the computer programming language (or operating system) to examine the operating system's file system and/or file structure to determine how to read/write lines/records and how they're delineated (if at all).     -- Gerard Schildberger (talk) 16:18, 3 August 2021 (UTC)

rename this task ?

Perhaps this (draft) task should be renamed to:

             Display the order of the lines of a file in reverse order 

--or--

             Display the order of the lines of a file in reverse 

... or somesuch wording.     -- Gerard Schildberger (talk) 16:30, 3 August 2021 (UTC)

Thank you. Done it--CalmoSoft (talk) 04:17, 4 August 2021 (UTC)

What is the order of the lines??? I'd prefer "Show the lines of a file in reverse order" suggested below

re-wording of the task requirements

I hope I got the re-wording of the (draft) task's requirements such that there is little room for misinterpretation.   My first draft change could've been interpreted as the original file was to be written with the reversed order of lines/records.   Also, I don't know if I got the "where to read" the lines/records,   so I tried to generalize   (memory = storage?).   We old-timers liked to use "core",   but that referred to different century.     -- Gerard Schildberger (talk) 20:03, 3 August 2021 (UTC)

Even worse

I had low expectations but even they were too high apparently. The task has been renamed form "Reverse file lines‎‎" to "Display the order of the lines of a file in reverse order". Assuming the task title has anything to do with the actual task to be performed; (a rash assumption for any of Calmosofts' tasks, I know.) it can adequately be executed in Raku as:

<lang perl6>say 'reversed'</lang>

as the order of the lines in a file in reverse order is pretty much by definition, "reversed". --Thundergnat (talk) 11:45, 4 August 2021 (UTC)

I renamed the task as you suggested.--CalmoSoft (talk) 13:58, 4 August 2021 (UTC)

I suggest "Reverse the order of lines in a text file while preserving the contents of each line." --Wherrera (talk) 14:40, 4 August 2021 (UTC)

I renamed the task as you suggested.--CalmoSoft (talk) 03:51, 5 August 2021 (UTC)

We seem to be heading towards over-specific task names - the name needn't be the task description :).
How about "Show the lines of a file in reverse order".
I like Nigel's observation that the task is to implement the Linux "tac" command, so maybe Implement the Linux "tac" command would be good (the task description could then say that only reading from standard input need be supported, text files only, native OS definition of a line, etc. etc. Perhaps multiple input files could then be a stretch goal ? --Tigerofdarkness (talk) 17:17, 4 August 2021 (UTC)

+1 obviously flattery will always do that, but in the interests of intellectual integrity I should point out that Laurence wrote the Unix Shell entry. I don't understand Walter Pachl's objection as tac rogers.txt does exactly what this task demands.--Nigel Galloway (talk) 14:52, 5 August 2021 (UTC)
I googled tac and see that tac actually accepts several files and "each file" and "separately" then make sense. I wonder, however, who needs this in real life. Rgds. --Walter Pachl 16:35, 5 August 2021 (UTC)

Here is the help text about unix tac:

copies each FILE (‘-’ means standard input),
or standard input if none are given,
to standard output, reversing the records
(lines by default) in each separately.

--Wherrera (talk) 17:40, 4 August 2021 (UTC)

from worse to worst: You are not changing the order of lines IN A TEXT FILE!!

"Show the lines of a file in reverse order" sounds perfect!

BTW The tac explanation doesn't impress me at all :-) ..Walter Pachl 06:51, 5 August 2021 (UTC)
Nor was I impressed with the Bash Tac command wordage.   It is slightly confusing with its verbiage   (as how it is (or could be) applied or used as per this Rosetta Code task's requirements.   It would fit better to be placed in the   discussion   page for this task instead of the task's preamble.     -- Gerard Schildberger (talk) 18:57, 5 August 2021 (UTC)
Return to "Reverse the order of lines in a text file while preserving the contents of each line" page.