Reverse the order of lines in a text file while preserving the contents of each line: Difference between revisions
Reverse the order of lines in a text file while preserving the contents of each line (view source)
Revision as of 20:25, 21 September 2021
, 2 years agoAda version
ReeceGoding (talk | contribs) (Added R.) |
(Ada version) |
||
Line 21:
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}}==
|