Reverse the order of lines in a text file while preserving the contents of each line: Difference between revisions
Content added Content deleted
(add sed) |
(add OCaml) |
||
Line 466: | Line 466: | ||
"Diplomacy is the art of |
"Diplomacy is the art of |
||
>>>>></pre> |
>>>>></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}}== |
=={{header|Pascal}}== |