Reverse the order of lines in a text file while preserving the contents of each line: Difference between revisions

Content added Content deleted
(Added R.)
(Ada version)
Line 21: Line 21:


Reference: [https://linuxhint.com/bash_tac_command/ Bash tac command]
Reference: [https://linuxhint.com/bash_tac_command/ Bash tac command]

=={{header|Ada}}==
<lang Ada>with Ada.Text_Io;
with Ada.Containers.Indefinite_Vectors;
with Ada.Command_Line;

procedure Reverse_Lines_In_File is

subtype Line_Number is Natural;

package Line_Vectors
is new Ada.Containers.Indefinite_Vectors
(Index_Type => Line_Number,
Element_Type => String);

use Line_Vectors,
Ada.Text_Io,
Ada.Command_Line;

File : File_Type;
Buffer : Vector;
begin
if Argument_Count = 1 then
Open (File, In_File, Argument (1));
Set_Input (File);
end if;

while not End_Of_File loop
Buffer.Prepend (Get_Line);
end loop;

if Is_Open (File) then
Close (File);
end if;

for Line of Buffer loop
Put_Line (Line);
end loop;

end Reverse_Lines_In_File;</lang>


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==