I am looking for a program that can find the longest line of a .txt
file. It should run on Microsoft Windows. Any license or price is fine.
-
How many characters shall a tab count? Just 1, 4 or 8 or customizable?– Thomas WellerJan 23, 2017 at 10:18
-
@Walmart - I think that your answers above should be put into an answer rather than left as comments.– Steve BarnesJan 23, 2017 at 16:27
2 Answers
I am looking for a program that can find the longest line of a .txt file. It should run on Microsoft Windows.
I've listed two FREE solutions below that may suffice for your need.
Method 1
You could use: wc -L "c:\folder\file.txt"
from the CoreUtils for Windows for example if you just need the number of the length of the longest line in that file. This would be a freebie too by the way.
Method 2
You can do this in Windows with PowerShell as well for a particular file:
Get the maximum length number of a record in a file:
GC "c:\folder\file.txt" | Measure -Property length -Maximum | Select Maximum
Get the content of the longest line/record in a file
GC "c:\folder\file.txt" | Sort -Property length | Select -last 1
Further Resources
-
1I would like to mention that if the file contains CTL language scripts like Devanagari, then use following command: GC "c:\folder\file.txt" -Encoding UTF8 | Sort -Property length | Select -last 1– ePanditSep 30, 2017 at 16:27
You can add an extension to Notepad++
to perform this operation. See this answer on SuperUser for details