{"id":10337,"date":"2019-07-14T17:23:27","date_gmt":"2019-07-14T11:53:27","guid":{"rendered":"http:\/\/198.58.113.91\/blog\/?p=10337"},"modified":"2022-07-24T08:20:39","modified_gmt":"2022-07-24T02:50:39","slug":"flip-or-reverse-text-file-contents-windows","status":"publish","type":"post","link":"https:\/\/www.winhelponline.com\/blog\/flip-or-reverse-text-file-contents-windows\/","title":{"rendered":"How to Flip or Reverse a Text File Using Different Ways in Windows"},"content":{"rendered":"<p>When analyzing plain-text log files such as the Web server logs or the <a href=\"https:\/\/www.winhelponline.com\/blog\/repair-windows-10-using-dism-sfc\/\">Sfc, or DISM<\/a> log files, you may sometimes prefer the most recent items appearing at the top. However, most of the log files that Windows generates would have the oldest entries listed first &#8212; entries listed in chronological order.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10338\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/reverse-lines-text-file-1.png\" alt=\"reverse lines in a text file windows\" width=\"699\" height=\"296\" \/><\/p>\n<p>You may be wondering how to reverse the lines in a log file (or any plain-text file, for that matter) so that the newest items appear at the top.\u00a0You can reverse the lines in a text file using several methods, of which some of them are covered in this article.<\/p>\n<div id=\"toc\">\n<h4>Reverse a text file in Windows<\/h4>\n<ol>\n<li><a href=\"#online\">Using free online sites\/services<\/a><\/li>\n<li><a href=\"#powershell\">Using PowerShell<\/a><\/li>\n<li><a href=\"#script\">Using VBScript<\/a><\/li>\n<li><a href=\"#notepad_plus\">Using Notepad++<\/a><\/li>\n<\/ol>\n<\/div>\n<p><em><strong>Note:<\/strong> As always, before proceeding, be sure to backup the original text file before manipulating it &#8212; e.g., using find\/replace, or running a script or macro against a text file.<\/em><\/p>\n<h2>Reverse a Text File Using Different Ways in Windows<\/h2>\n<h3><a id=\"online\"><\/a>Method 1: Using online portals (free)<\/h3>\n<p>There are several free online services to reverse the order of the lines in a text file for you. Here is a couple of useful sites:<\/p>\n<pre>Sort Text Lines - Text Mechanic: <strong>https:\/\/textmechanic.co\/Sort-Text-Lines.html<\/strong>\r\nBig File Tool - Sort Lines: <strong>https:\/\/textmechanic.co\/Big-File-Tool-Sort-Lines.html<\/strong>\r\nReverse Lines: <strong>https:\/\/www.miniwebtool.com\/reverse-lines\/<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10339\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/reverse-lines-text-file-2.png\" alt=\"reverse lines in a text file windows\" width=\"701\" height=\"433\" \/><\/p>\n<h3><a id=\"powershell\"><\/a>Method 2: Using PowerShell<\/h3>\n<p>To reverse the order of the lines in a text file using PowerShell, use this command-line syntax from a PowerShell window:<\/p>\n<pre>$x = Get-Content -Path \"C:\\Users\\ramesh\\Desktop\\dism.log\"; Set-Content -Path \"C:\\Users\\ramesh\\Desktop\\dism.log\" -Value ($x[($x.Length-1)..0])<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10340\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/reverse-lines-text-file-3.png\" alt=\"reverse lines in a text file windows powershell\" width=\"698\" height=\"500\" \/><\/p>\n<h3><a id=\"script\"><\/a>Method 3: Using VBScript<\/h3>\n<p>Make a VBScript file from the following contents. To do so, open Notepad, copy the following lines into it and save the file with .vbs extension &#8212; e.g. <code>reverse_text_file.vbs<\/code><\/p>\n<pre>'Script to reverse the lines in a text file. Takes a text file name as the argument.\r\nIf\u2002Wscript.arguments.count\u2002=\u20020\u2002Then\u2002wscript.quit\r\nDim\u2002sFileName\r\nsFileName\u2002=\u2002Wscript.arguments(0)\r\nConst\u2002ForReading\u2002=\u20021\r\nConst\u2002ForWriting\u2002=\u20022\r\nConst\u2002TriStateTrue\u2002=\u2002-1\r\nDim\u2002arrLines()\r\ni\u2002=\u20020\r\nSet\u2002objFSO\u2002=\u2002CreateObject(\"Scripting.FileSystemObject\")\r\nSet\u2002objFile\u2002=\u2002objFSO.OpenTextFile(sFileName,\u2002ForReading,\u2002TriStateTrue)\r\nDo\u2002Until\u2002objFile.AtEndOfStream\r\n\u2002\u2002\u2002ReDim\u2002Preserve\u2002arrLines(i)\r\n\u2002\u2002\u2002arrLines(i)\u2002=\u2002objFile.ReadLine\r\n\u2002\u2002\u2002i\u2002=\u2002i\u2002+\u20021\r\nLoop\r\nobjFile.Close\r\nSet\u2002objFile\u2002=\u2002objFSO.OpenTextFile(sFileName,\u2002ForWriting,\u2002TriStateTrue)\r\nFor\u2002i\u2002=\u2002Ubound(arrLines)\u2002To\u2002LBound(arrLines)\u2002Step\u2002-1\r\n\u2002\u2002\u2002objFile.WriteLine\u2002arrLines(i)\r\nNext\r\nobjFile.Close\r\nWscript.echo\u2002\"Done\"\r\n<\/pre>\n<p>To run the VBScript file, use the following command-line syntax:<\/p>\n<pre>cscript \/\/nologo reverse_text_file.vbs \"d:\\logs\\somefile.txt\"<\/pre>\n<p>or<\/p>\n<pre>wscript reverse_text_file.vbs \"d:\\logs\\somefile.txt\"<\/pre>\n<p><em>Alternately, drag the text file on the VBScript file to reverse the text file contents.<\/em><\/p>\n<p>You may also place a VBScript shortcut to the Send To folder for easier access. In the <a href=\"https:\/\/www.winhelponline.com\/blog\/shell-commands-to-access-the-special-folders\/\">Send To folder<\/a> of your user account, create a shortcut to the VBScript with wscript.exe prefix &#8212; e.g. <code>wscript.exe d:\\reverse-text-file.vbs<\/code> and customize its icon and shortcut caption.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10342\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/reverse-text-file-vbscript-sendto.png\" alt=\"reverse lines in a text file windows vbscript\" width=\"700\" height=\"769\" \/><\/p>\n<h3><a id=\"notepad_plus\"><\/a>Method 4: Using Notepad++<\/h3>\n<p>To reverse the lines in a text file using Notepad++, first, you&#8217;ll need to add serial number prefix for each line. Then reverse the lines (lexicographically descending), and then finally <a href=\"https:\/\/www.winhelponline.com\/blog\/notepad-plus-find-and-replace-text\/#remove_number_of_chars_beginning_line\">remove the serial numbers<\/a>. Follow these steps:<\/p>\n<ol>\n<li>Open the text file using Notepad++<\/li>\n<li>Select all the contents via Edit &rarr; Select All<\/li>\n<li>From the Edit menu, select Column Editor<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10345\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/reverse-text-file-notepad-plus-1.png\" alt=\"reverse lines in a text file notepad++\" width=\"335\" height=\"385\" \/><\/li>\n<li>Select the <strong>Number to Insert<\/strong> radio button.<\/li>\n<li>Set Initial number: to <code>1<\/code><\/li>\n<li>Set Increase by: to <code>1<\/code><\/li>\n<li>Enable <strong>Leading zeros<\/strong>, and click OK. This adds the line number or the serial number before each line.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10344\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/reverse-text-file-notepad-plus-2.png\" alt=\"reverse lines in a text file notepad++\" width=\"701\" height=\"322\" \/><\/li>\n<li>From the Edit menu, click <strong>Line Operations<\/strong> &rarr; <strong>Sort Lines Lexicographically Descending<\/strong>.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10343\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/reverse-text-file-notepad-plus-3.png\" alt=\"reverse lines in a text file notepad++\" width=\"699\" height=\"199\" \/><br \/>\nThe lines in the text file are now reversed. The total number of lines in this example is <code>17612<\/code> (i.e. <strong><code>5<\/code><\/strong> digits).\u00a0Now, you&#8217;ll need to <a href=\"https:\/\/www.winhelponline.com\/blog\/notepad-plus-find-and-replace-text\/#remove_number_of_chars_beginning_line\">remove the first five characters<\/a> (Sl. no) in each line.<\/li>\n<li>Go to the 1st line in the text file, and press <kbd>Ctrl<\/kbd> + <kbd>H<\/kbd> to launch the Find &amp; Replace dialog.<\/li>\n<li>In the Find what: text box, type <code>^.{5}(.*)$<\/code><\/li>\n<li>In the Replace with: box, type <code>$1<\/code><\/li>\n<li>Set the Search Mode to <strong>Regular expression<\/strong><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10346\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/reverse-text-file-notepad-plus-4.png\" alt=\"reverse lines in a text file notepad++\" width=\"573\" height=\"356\" \/><\/li>\n<li>Click Replace All. That&#8217;s it. The first five characters are removed.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10347\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/reverse-text-file-notepad-plus-5.png\" alt=\"reverse lines in a text file notepad++\" width=\"699\" height=\"203\" \/><\/li>\n<li>Save the file and close Notepad++.<\/li>\n<\/ol>\n<div class=\"rp\"><strong>RELATED:<\/strong> <a href=\"https:\/\/www.winhelponline.com\/blog\/notepad-plus-find-and-replace-text\/\">Notepad++ Tips: Find and Replace, and Text Manipulation Examples<\/a><\/div>\n<p>This reverses the lines in your text file!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When analyzing plain-text log files such as the Web server logs or the Sfc, or DISM log files, you may sometimes prefer the most recent items appearing at the top. However, most of the log files that Windows generates would have the oldest entries listed first &#8212; entries listed in chronological order. You may be &#8230; <a title=\"How to Flip or Reverse a Text File Using Different Ways in Windows\" class=\"read-more\" href=\"https:\/\/www.winhelponline.com\/blog\/flip-or-reverse-text-file-contents-windows\/\" aria-label=\"Read more about How to Flip or Reverse a Text File Using Different Ways in Windows\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[7],"tags":[339,396,480],"class_list":["post-10337","post","type-post","status-publish","format-standard","hentry","category-windows","tag-notepad","tag-powershell","tag-scripts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":4426,"url":"https:\/\/www.winhelponline.com\/blog\/find-amount-words-lines-chars-text-file-powershell\/","url_meta":{"origin":10337,"position":0},"title":"Find the Amount of Words, Chars and Lines in a Text File Using PowerShell","author":"Ramesh","date":"October 23, 2016","format":false,"excerpt":"If you're still using the good, old Notepad to craft essays or content for your Website, and want to know the number of characters used in a text file, here is a PowerShell cmdlet that will help.PowerShell has a built-in cmdlet named \"Measure-Object\". It calculates the property values of certain\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"get word count in text file","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/get-word-count-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/get-word-count-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/get-word-count-1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3922,"url":"https:\/\/www.winhelponline.com\/blog\/empty-recycle-bin-task-scheduler-powershell-clear-recyclebin-nircmd\/","url_meta":{"origin":10337,"position":1},"title":"Empty Recycle Bin Automatically Using Task Scheduler or Storage Sense","author":"Ramesh","date":"August 31, 2016","format":false,"excerpt":"You can use it to clear the Recycle Bin at a specified time or regular intervals with Task Scheduler using a PowerShell command. Alternately, you can also use Storage Settings (a.k.a. Storage Sense) to clear the files from Recycle Bin that are older than a certain number of days. This\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"empty recycle bin - storage settings or storage sense","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/storage-settings-cleanup-enable.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/storage-settings-cleanup-enable.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/storage-settings-cleanup-enable.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/storage-settings-cleanup-enable.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":31098,"url":"https:\/\/www.winhelponline.com\/blog\/collect-diagnostic-logs-windows\/","url_meta":{"origin":10337,"position":2},"title":"How to Collect Diagnostic Logs in Windows","author":"Ramesh","date":"December 21, 2022","format":false,"excerpt":"There are many different types of diagnostic logs in Windows. Each log is to diagnose a specific component. The Windows Update client creates the Windows Update ETL or Windows Update log files, the Component-Based Servicing uses \"cbs.log\", and the DISM tool writes to \"dism.log\", etc. Besides the native logs, you\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"Farbar Recovery Scan Tool - FRST - FRST64.exe","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2022\/12\/farbar.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2022\/12\/farbar.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2022\/12\/farbar.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":35642,"url":"https:\/\/www.winhelponline.com\/blog\/new-text-document-missing-windows-11\/","url_meta":{"origin":10337,"position":3},"title":"New &#8220;Text Document&#8221; missing from Right-Click menu in Windows 11","author":"Ramesh","date":"April 3, 2023","format":false,"excerpt":"When you right-click on the desktop and click \"New,\" the New menu may not contain the \"Text Document\" option on your Windows 11 computer. This article tells you how to bring the \"Text Document\" option back. Restore Missing \"Text Document\" to the New menu To add \"Text Document\" to the\u2026","rel":"","context":"In &quot;Windows 11&quot;","block_context":{"text":"Windows 11","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-11\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5894,"url":"https:\/\/www.winhelponline.com\/blog\/search-contents-of-any-file-windows-search-indexing\/","url_meta":{"origin":10337,"position":4},"title":"How to Search the Contents of Any File Type Using Windows Search","author":"Ramesh","date":"November 1, 2017","format":false,"excerpt":"Windows Search and its Advanced Query Syntax (AQS) is a freaking awesome feature in Windows. It lets you quickly find a particular file or group of files with a specific name or metadata, in a folder and sub-folders. Along with indexing file properties or metadata, most known plain-text files are\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"indexing options start menu search","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2017\/11\/indexing-options.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":80266,"url":"https:\/\/www.winhelponline.com\/blog\/enable-preview-of-log-files-explorer\/","url_meta":{"origin":10337,"position":5},"title":"How to Enable Preview of .LOG Files in File Explorer","author":"Ramesh","date":"February 16, 2026","format":false,"excerpt":"By default, the preview capability exists for most text-based files in File Explorer. However, for some file types, such as .log or .py, a preview may not be generated by default and you see the message \"No preview available\" in the preview pane in File Explorer. You can enable preview\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/10337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/comments?post=10337"}],"version-history":[{"count":0,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/10337\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/media?parent=10337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/categories?post=10337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/tags?post=10337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}