Reverse the order of lines in a text file while preserving the contents of each line: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(add sed) |
||
Line 780: | Line 780: | ||
</pre> |
</pre> |
||
=={{header| |
=={{header|sed}}== |
||
<syntaxhighlight lang="sed">1!G |
|||
{{works with|Bourne Again SHell}} |
|||
h |
|||
$!d</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
$ sed -f tac.sed file.txt |
|||
--- Will Rodgers |
|||
until you can find a rock." |
|||
saying 'Nice Doggy' |
|||
"Diplomacy is the art of |
|||
</pre> |
|||
=={{header|UNIX Shell}}== |
|||
<syntaxhighlight lang="bash">tac rodgers.txt</syntaxhighlight> |
<syntaxhighlight lang="bash">tac rodgers.txt</syntaxhighlight> |
||
{{out}} |
|||
Output: |
|||
<pre> |
<pre> |
||
--- Will Rodgers |
--- Will Rodgers |
||
Line 792: | Line 806: | ||
"Diplomacy is the art of |
"Diplomacy is the art of |
||
</pre> |
</pre> |
||
Notice that '''tac''' is '''cat''' in reverse order. |
Notice that '''tac''' is '''cat''' in reverse order. |
||