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

m
(add sed)
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 3 users not shown)
Line 466:
"Diplomacy is the art of
>>>>></pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let rec read_lines_reverse lst =
match read_line () with
| line -> read_lines_reverse (line :: lst)
| exception End_of_file -> lst
 
let () = read_lines_reverse [] |> List.iter print_endline</syntaxhighlight>
{{out}}
<pre>
$ ocaml tac.ml <file.txt
--- Will Rodgers
 
until you can find a rock."
saying 'Nice Doggy'
"Diplomacy is the art of
</pre>
 
=={{header|Pascal}}==
Line 612 ⟶ 629:
C:\My Projects\BGI>
</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ sharefile drop
[] swap
[ carriage over find split
dup $ "" != while
behead drop
unrot nested swap join
swap again ]
drop nested swap join
witheach [ echo$ cr ] ] is task ( $ --> )
 
$ "rosetta/input.txt" task</syntaxhighlight>
 
{{out}}
 
<pre> --- Will Rodgers
until you can find a rock."
saying 'Nice Doggy'
"Diplomacy is the art of
</pre>
 
=={{header|R}}==
<syntaxhighlight lang="rsplus">text <- scan("Rodgers.txt", character(), sep = "\n")
Line 780 ⟶ 821:
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">puts File.readlines("diplomacy.txt").reverse</syntaxhighlight>
{{out}}
<pre> --- Will Rodgers
 
until you can find a rock."
saying 'Nice Doggy'
"Diplomacy is the art of
</pre>
=={{header|sed}}==
<syntaxhighlight lang="sed">1!G
Line 794 ⟶ 844:
 
</pre>
 
 
=={{header|UNIX Shell}}==
Line 810 ⟶ 859:
=={{header|Wren}}==
{{libheader|Wren-ioutil}}
<syntaxhighlight lang="ecmascriptwren">import "./ioutil" for File, FileUtil
 
var fileName1 = "rodgers.txt"
9,476

edits