Home / Text tools / Reverse lines

Reverse Lines

Reverse the order of the lines in a list or a text, so that the last line comes first. You can also reverse the letters in every line.

Result

Flip a list upside down

Paste a list with one item per line and the order is reversed: the last line comes first and the first line comes last. The lines themselves are not changed.

First        Fourth
Second  =>   Third
Third        Second
Fourth       First

When it helps

  • Log files and exports that list the oldest entry first, when you want the newest at the top.
  • Ranked lists that are written from the bottom to the top, such as a countdown.
  • Chat logs and notes that were saved in the wrong order.
  • Preparing data before you sort, remove duplicates or load it into a spreadsheet.

Options

  • Trim spaces: removes spaces from the start and end of every line.
  • Remove empty lines: drops blank lines, so the result is a clean list.

The second mode, Reverse the letters in each line, keeps the lines in their order and writes each line backwards.

In the command line

tac file.txt          # reverse the order of the lines (Linux)
rev file.txt          # reverse the letters in each line (Linux)
sort -r file.txt      # sort in reverse alphabetical order, which is different

Reversing the lines is not the same as sorting in reverse. A reverse sort puts the lines in Z to A order, while reversing only flips the order that they already have. To sort, use sort lines.

For the order of words, see reverse words, and for random order, shuffle lines. The reverse text page has every mode in one place.

Frequently asked questions

How do I reverse the order of lines?

Paste the text in the box. The last line becomes the first, and the first becomes the last.

Is reversing lines the same as sorting Z to A?

No. Reversing flips the existing order. A reverse sort orders the lines alphabetically from Z to A.

Can I remove blank lines at the same time?

Yes. Tick Remove empty lines and Trim spaces.

What is the command for this in Linux?

tac reverses the lines of a file. rev reverses the letters in each line.