2

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.

  • Do you need something that will show just the number of the longest line in a particular file or do you need it to tell you how long it is plus the line number? For example image a two line file with abc on one line and abcd on another line. Do you need it to tell you 4 for the longest length of line in that file or do you need it to tell you it's 4 for than and also that it's on line number it sits within the file? – Pimp Juice IT Jan 23 '17 at 4:56
  • You could use wc -L "c:\users\user\desktop\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. – Pimp Juice IT Jan 23 '17 at 5:01
  • It appears 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 1. GC "c:\folder\file.txt" | Measure -Property length -Maximum | Select Maximum and/or also get the content of the longest line/record in a file 2. GC "c:\folder\file.txt" | Sort -Property length | Select -last 1 ...... Another freebie!! – Pimp Juice IT Jan 23 '17 at 5:19
  • Just to recap, you can get.... 1.) the line character position\column number of the record in a file with the longest length. 2.) the actual content of the longest records in a file. 3.) the line number itself within a file for the record\row which contains the longest records length. I'll be happy to add an answer for you if you confirm one of the methods I listed works for you need, etc. I just haven't dug into getting the line number but there's three method for getting that data from a file's records as explained. – Pimp Juice IT Jan 23 '17 at 5:23
  • How many characters shall a tab count? Just 1, 4 or 8 or customizable? – Thomas Weller Jan 23 '17 at 10:18
3

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:

  1. Get the maximum length number of a record in a file:

    GC "c:\folder\file.txt" | Measure -Property length -Maximum | Select Maximum

  2. Get the content of the longest line/record in a file

    GC "c:\folder\file.txt" | Sort -Property length | Select -last 1


Further Resources

  • 1
    I 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 – ePandit Sep 30 '17 at 16:27
0

You can add an extension to Notepad++ to perform this operation. See this answer on SuperUser for details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.