0

I have an ASCII CSV file containing a looooong line (7956 characters). When I use find.exe to extract that line, it only prints the first 4095 bytes. Plus it appends no line feed, so the next hit (or whatever I add) gets glued to (4095 bytes of) the long line in the result.

When using the /N option, the prepended [<line number>] also counts, so the printed line still is 4095 bytes long (more is truncated).

I assume this is a bug...? Is there any workaround?

Michel de Ruiter
  • 7,131
  • 5
  • 49
  • 74
  • 2
    Please read the Microsoft documentation page [Command prompt (Cmd. exe) command-line string limitation](https://learn.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/command-line-string-limitation). The solution is using a PowerShell script for the task which has built-in true CSV support and does not have the command line length limitation. `%SystemRoot%\System32\find.exe` is even more limited and supports only lines up to 4095 characters (4094 characters + line-feed + terminating null byte) because of using most likely a character array with a fixed size of `4096`. – Mofi Dec 19 '22 at 17:09
  • `%SystemRoot%\System32\findstr.exe` supports lines up to 8191 characters (8190 characters + line-feed + terminating null byte) and outputs an error like `FINDSTR: Line 5 is too long.` if a line has even more characters. __FINDSTR__ uses obviously a character array with a fixed size of `8192`. – Mofi Dec 19 '22 at 17:12
  • 2
    BTW: The line length limitations of __FIND__ and __FINDSTR__ are not bugs, just limitations not documented by Microsoft on the appropriate [Windows commands](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands) documentation page. The documentations on SS64 in [An A-Z Index of Windows CMD commands](https://ss64.com/nt/) for __FIND__ and __FINDSTR__ are better, but also not 100% complete for all use cases according to line length limitation of __FIND__. See also: [FINDSTR - Escapes and Length limits](https://ss64.com/nt/findstr-escapes.html) – Mofi Dec 19 '22 at 17:27
  • I recommend to read [What are the undocumented features and limitations of the Windows FINDSTR command?](https://stackoverflow.com/questions/8844868/what-are-the-undocumented-features-and-limitations-of-the-windows-findstr-comman) __FIND__ outputs just the first 4095 characters without a line-feed if it has to output lines with more than 4094 characters before (carriage return +) line-feed resulting in the output of a single, very long line on searching in a CSV file for a string found in the first 4095 characters of lines and all found lines exceed this line length limitation. – Mofi Dec 19 '22 at 17:35
  • Great finds! If you make your comments into an answer, I can accept it as such. But I don't think the command line limitation applies to `find.exe`. – Michel de Ruiter Dec 20 '22 at 12:37

0 Answers0