How to Reverse Line Order in a Text File (3 Safe Methods)
Flip a list from bottom to top without reversing its words or letters. Learn safe methods in Notepad++, PowerShell, and GNU tac, plus fixes for blank lines, headers, and encoding.
To reverse line order in a text file, move the last line to the top, the second-to-last line below it, and continue until the first line becomes the last. The words, punctuation, and letters inside each line should stay in their original order.
For a quick, no-code solution on Windows, use Edit → Line Operations → Reverse Line Order in Notepad++. For a repeatable file-based workflow, use PowerShell or GNU tac. All three methods below can flip a list without turning readable text into backwards characters.
The important part is choosing the right unit to reverse. A line, a word, a character, and a structured data record are not necessarily the same thing.
What reversing line order actually does
Suppose your file contains this three-line list:
Draft the outline
Write the article
Check the links
Reversing its line order produces:
Check the links
Write the article
Draft the outline
Notice that “Check the links” still reads normally. This is not character reversal, which would turn that line into “sknil eht kcehC”. It is also not word reversal, which would produce “links the Check”.
A useful rule is: keep each line intact and reverse only the sequence of lines. That works for one-item-per-line lists, simple exports, and logs where each event occupies exactly one line.
If you actually want to change word order inside a sentence, see how to reverse words without scrambling the letters. For character and word transformations, the Text Reverser tool offers separate modes. Those modes are different from a dedicated line-order operation; do not assume a full-text reversal will preserve the contents of each line.
Choose the right method
- Notepad++: best for an occasional edit, a visual check, or reversing just part of a document.
- PowerShell: useful for a repeatable local workflow with explicit input and output paths.
- GNU tac: a concise terminal command on Linux and other environments where GNU Coreutils is installed.
If your data is already in a spreadsheet, keep related columns together and reverse complete rows rather than one isolated column. Our Excel text-reversal guide covers the difference between letters, words, and lists.
Before using any method, save a copy. Choose a new output filename, such as reversed.txt, rather than overwriting your only original. Make sure an older file with that output name does not contain something you need.
Method 1: Reverse line order in Notepad++
Notepad++ has a built-in command for this task. It is a separate application from the standard Windows Notepad.
- Open the text file in Notepad++.
- Choose File → Save As and create a working copy.
- Decide whether to reverse the whole document or a selected section.
- For the whole document, clear any active selection. For a section, select only the lines you want to move.
- Choose Edit → Line Operations → Reverse Line Order.
- Inspect the first and last few lines, then save the copy.
The Notepad++ editing manual confirms that the command reverses selected lines, or the entire current document when there is no active selection. You do not need to install a plugin for the documented command.
Keep a heading at the top
Consider this list:
Shopping list
Apples
Bread
Carrots
Reversing the whole document moves “Shopping list” to the bottom. If that is a heading rather than an item, select only the three item lines before using the command. The result should be:
Shopping list
Carrots
Bread
Apples
Be careful at selection boundaries. A selection that touches another line can include more than you intended. After the operation, confirm that the heading and the first unselected line have not moved.
Do not choose descending sort instead
“Reverse Line Order” and “Sort Descending” solve different problems. Reversal flips the sequence that already exists. Sorting creates a new sequence based on text or numeric values.
For example, reversing pear, apple, banana gives banana, apple, pear. Alphabetical descending order gives pear, banana, apple. If the original list represents a deliberate priority or reading order, sorting cannot reliably reconstruct its opposite.
Method 2: Reverse a text file with PowerShell
PowerShell can read a file as lines, reverse the collection, and write the result to a different file. The following example assumes the source file is UTF-8 text.
Change the two paths to match your files, then run:
$InputPath = 'C:\data\input.txt'
$OutputPath = 'C:\data\reversed.txt'
$lines = @(Get-Content -LiteralPath $InputPath -Encoding utf8)
[array]::Reverse($lines)
Set-Content -LiteralPath $OutputPath -Value $lines -Encoding utf8
Here is what each part does:
Get-Contentreads the file as separate lines rather than one large string.@(...)makes the result an array even when the file contains only one line.[array]::Reverse($lines)reverses those array elements in place. It does not reverse the characters inside each element.Set-Contentwrites the reordered text to the output file.-LiteralPathtreats the supplied filename literally instead of interpreting wildcard characters.
Microsoft documents the line-reading behavior in Get-Content and the writing options in Set-Content.
The entire line collection is held in memory. This is convenient for everyday lists, but do not assume it is the right approach for a very large log file on a machine with limited memory.
Understand the encoding trade-off
This is a text transformation, not a byte-for-byte preservation technique. Reading and rewriting the file can change its encoding marker, line endings, and final newline.
In Windows PowerShell 5.1, -Encoding utf8 writes UTF-8 with a byte order mark, often called a BOM. In PowerShell 7, it writes UTF-8 without a BOM. PowerShell 7 also provides explicit utf8BOM and utf8NoBOM choices when another application requires a particular convention. Microsoft explains the differences in its character encoding guide.
If the source is not UTF-8, choose its actual encoding when reading it. A successful command does not guarantee that accented letters were decoded correctly. Open the output and inspect representative non-English text before replacing anything.
Also, do not add -NoNewline to this example as a quick fix. With an array of strings, suppressing separators can concatenate lines. Preserving an exact newline convention requires a more deliberate read-and-write strategy.
Method 3: Reverse lines with GNU tac
On a system with GNU Coreutils, tac reverses records, using the newline character as the default separator. For a normal newline-terminated text file, the command is:
tac -- input.txt > reversed.txt
The input file stays separate from the output. The -- marks the end of command options, which is useful when a filename might begin with a hyphen.
For a path containing spaces, quote it:
tac -- "reading list.txt" > "reading list reversed.txt"
Never redirect output back to the same input file:
# Do not run this:
tac -- input.txt > input.txt
The shell can truncate the destination before tac reads it. That can destroy the original content instead of reversing it. A separate output file is a simple, important safeguard.
The GNU tac manual describes the record and separator behavior. Unlike a text-decoding workflow, tac rearranges records without interpreting each character. That makes it useful for ordinary UTF-8 or ASCII-compatible newline-delimited files, but it is not a universal solution for every encoding. Do not apply the same assumption to UTF-16 files.
Watch out for a missing final newline
A file can display as three lines even if the last one has no terminating newline. With GNU tac, the separator normally belongs to the record before it. That detail can produce a surprising result when the last record is unterminated.
For example, an input containing Alpha\nBeta\nGamma, with no newline after “Gamma”, can produce GammaBeta\nAlpha\n. The first two visible entries become joined.
For a plain list where adding a final newline is acceptable, open a copy in a text editor, place the cursor after the final item, press Enter once, and save before running tac. Do not blindly add another newline to a file that already has one, because you may create an extra blank record.
GNU tac is not guaranteed to be installed on every Unix-like operating system. If the command is unavailable, use an environment with GNU Coreutils or choose another method from this guide rather than assuming every system has an identical command.
Blank lines, wrapped lines, and records: what can go wrong?
Blank lines move too
A blank line is not automatically discarded. In a simple line-based reversal, it moves to the opposite position along with other lines.
If a blank line separates two paragraphs, reversing individual lines may scatter the paragraph structure. Decide whether your actual unit is a single line, a paragraph, or a block of related lines. These methods target single physical lines, not semantic paragraphs.
Removing blank lines first is a separate edit. Do it only if that is intentional, and keep the untouched original so you can recover meaningful spacing.
Word wrap is not a line break
A long sentence may wrap across three screen rows while remaining one physical line in the file. Resizing the editor changes the display, not the underlying text.
If the result seems not to move the way you expected, turn off word wrap or inspect line numbers. You may have several visible rows but only one newline-delimited item. Avoid inserting hard line breaks merely to imitate the current screen width unless that change is part of your goal.
CSV rows and log entries can span multiple lines
Do not reverse a CSV file by physical line if quoted fields contain embedded newlines. You can split one record into pieces and produce invalid data. Similarly, a log event may contain a timestamp line followed by a multi-line stack trace; reversing every line separates the explanation from its event.
Use a format-aware parser to reverse complete records in those cases. For a CSV with a header, the header should normally remain at the top while only the data records change order. A plain text command cannot infer that structure for you.
Newest-first is not always the same as reversed
Reversing a log makes it newest-first only if its original sequence was reliably oldest-first. Files merged from several sources may already contain out-of-order timestamps.
If your goal is chronological sorting, parse and sort the timestamp field. If your goal is simply the opposite of the current order, reverse the lines. Keeping those two intentions separate prevents plausible-looking but incorrect results.
A quick check before you use the result
Before replacing the source or importing the output elsewhere, check these five things:
- Endpoints: the original last item should now be first, and the original first item should now be last, excluding any heading you deliberately kept fixed.
- Contents: the words, spaces, punctuation, and characters inside a sample line should be unchanged.
- Completeness: duplicates and blank entries should still be present unless you intentionally removed them.
- Structure: headings, multi-line records, and related columns should not have been separated from their data.
- File format: confirm the encoding and newline convention are acceptable to the application that will read the file.
As a logical check, reversing the same sequence twice should restore its original order. That does not prove the files are byte-identical: a text editor or writer may still normalize line endings or encoding.
Frequently asked questions
Can I reverse a list without reversing its letters?
Yes. Reverse the sequence of complete lines, not the character sequence. Notepad++'s Reverse Line Order command, the PowerShell array method, and GNU tac all address line order, with the file-format caveats described above.
Is reversing lines the same as sorting Z to A?
No. Reversal uses the existing positions. Descending sorting compares the contents and builds a new order. They match only when the original list already happens to be sorted in the corresponding ascending order.
Will reversing lines fix backwards text?
Not if the letters themselves are backwards. A line-order operation leaves those letters untouched. Use a character reverser for a reversed character sequence, and first identify whether the whole text or each word was reversed.
Which method should I start with?
For a one-off edit on Windows, Notepad++ is easy to inspect visually. Use PowerShell for a repeatable text-file workflow, or GNU tac when it is available in your terminal and your input suits its newline-based record model. Whatever you choose, work on a copy and verify the result before overwriting the original.
Try the Text Reverser tool
Reverse text, words, or letters instantly — free and entirely in your browser.
Open the tool