Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 7
    This is a good solution, but some explanation for how this works will be even better. Commented Mar 16, 2011 at 11:19
  • 17
    It's a famous sed one-liner. See "36. Reverse order of lines (emulate "tac" Unix command)." in Famous Sed One-Liners Explained for a full explanation of how it works. Commented Mar 16, 2011 at 11:37
  • 7
    Perhaps worth noting: "These two one-liners actually use a lot of memory because they keep the whole file in hold buffer in reverse order before printing it out. Avoid these one-liners for large files." Commented Mar 17, 2011 at 14:33
  • So do all the other answers (except maybe the one using sort - there's a chance it will use a temporary file). Commented Apr 15, 2011 at 20:39
  • 2
    Note that tac is faster for regular files because it reads the file backward. For pipes, it has to do the same as the other solutions (hold in memory or in temp files), so is not significantly faster. Commented Sep 14, 2012 at 5:48