| Author |
Message |
|
aGerman
Expert
Joined: 22 Jan 2010 18:01 Posts: 1395 Location: Germany
|
 Re: Undocumented FINDSTR features and limitations
Haha, no I also didn't want to discredit Dave. He already mentioned it was untested. I corrected this for all the Google users who stumble upon this thread Regards aGerman
|
| 22 Jan 2012 15:20 |
|
 |
|
dbenham
Expert
Joined: 12 Feb 2011 21:02 Posts: 889 Location: United States (east coast)
|
 Re: Undocumented FINDSTR features and limitations
I updated my SO post: http://stackoverflow.com/a/8844873/1012053I used to think that the Windows pipe operator appended <CR><LF> to the input if the last character in the stream was not a <LF>. But I've since discovered that FINDSTR is actually doing the alteration of the input. FINDSTR also appends <CR><LF> to redirected input on Vista (and XP?) if the last character of the redirected file is not <LF>. I've discovered a nasty FINDSTR "feature" running on Windows 7: it hangs indefinitely on Windows 7 if you search redirected input and the redirected file does not end with <LF>. Dave Benham
|
| 06 Jun 2012 21:13 |
|
 |
|
Fawers
Joined: 08 Apr 2012 17:11 Posts: 187
|
 Re: Undocumented FINDSTR features and limitations
How could I not see this before? I have so many doubts on using FINDSTR.
Added this page to my favs. Gonna read it when I've got enough time to. Thanks, Dave.
|
| 06 Jun 2012 21:48 |
|
 |
|
foxidrive
Joined: 10 Feb 2012 02:20 Posts: 2484
|
 Re: Undocumented FINDSTR features and limitations
dbenham wrote: FINDSTR also appends <CR><LF> to redirected input on Vista (and XP?) if the last character of the redirected file is not <LF>. I've discovered a nasty FINDSTR "feature" running on Windows 7: it hangs indefinitely on Windows 7 if you search redirected input and the redirected file does not end with <LF>. XP also has the issue if the file does not end with appropriate line endings. It hangs.
|
| 06 Jun 2012 21:57 |
|
 |
|
dbenham
Expert
Joined: 12 Feb 2011 21:02 Posts: 889 Location: United States (east coast)
|
 Re: Undocumented FINDSTR features and limitations
I updated my SO FINDSTR post with two new sections: 1) Description of XP behavior displaying most control characters as dots 2) Bugged /S and /D options may fail to find files if short 8.3 names are encountered. Dave Benham
|
| 27 Nov 2012 21:29 |
|
 |
|
carlos
Joined: 20 Aug 2010 13:57 Posts: 88
|
 Re: Undocumented FINDSTR features and limitations
Thanks. I remember that the default is /R not /L. Example: print # but Code: echo.#|Findstr /L "." don't print anything. The default is /R not /L
|
| 27 Nov 2012 22:02 |
|
 |
|
dbenham
Expert
Joined: 12 Feb 2011 21:02 Posts: 889 Location: United States (east coast)
|
 Re: Undocumented FINDSTR features and limitations
I think you did not read the post carefully. It is more complicated than that. I stated that the default for the /C option is literal. The default for all other methods (anything other than /C option) depends on the content of the 1st search string. If the 1st search string contains an un-escaped meta character and the string is a valid regex, then all searches will be treated as regex. If the first string does not contain an un-escaped meta character, or if it is not a valid regex, then all search strings will be treated as literals. The following is a regex search that matches because the first string is a valid regex that contains a meta character. Code: echo #|findstr ". a"
But this next example is a literal search that does not match because the first search string does not contain a meta character Code: echo #|findstr "a ."
Dave Benham
|
| 27 Nov 2012 23:18 |
|
 |
|
carlos
Joined: 20 Aug 2010 13:57 Posts: 88
|
 Re: Undocumented FINDSTR features and limitations
Thanks for the info. When I specify /L or /R using the /C option, I get a message that says that the /C option was omitted. Code: C:\Users\Carlos>echo.#|findstr /c /l "#" FINDSTR: se ha omitido /c #
C:\Users\Carlos>echo.#|findstr /c /r "#" FINDSTR: se ha omitido /c #
Also, I have a dude with the /O option. I have these file: If I use: Code: findstr /N /O "#" file.txt it print: Code: 1:0:all#everybody#is#ok
The offset should be 3 not 0?
|
| 28 Nov 2012 00:18 |
|
 |
|
foxidrive
Joined: 10 Feb 2012 02:20 Posts: 2484
|
 Re: Undocumented FINDSTR features and limitations
It seems buggy,
file.txt d#dd aaaa#aa# all#everybody#is#ok aaa
d:\ABC>findstr /O /c:"#" file.txt 0:d#dd 6:aaaa#aa# 16:all#everybody#is#ok
|
| 28 Nov 2012 03:13 |
|
 |
|
dbenham
Expert
Joined: 12 Feb 2011 21:02 Posts: 889 Location: United States (east coast)
|
 Re: Undocumented FINDSTR features and limitations
Here again, the correct information is already in my SO post. SO FINDSTR post wrote: lineOffset: = The decimal byte offset of the start of the matching line, with 0 representing the 1st character of the 1st line. Only printed if /O option is specified.
Note - it is the byte offset of the beginning of the line that matches (measured from the beginning of the file), not the offset of the beginning of the match itself. Also, don't forget to count the CarriageReturn/LineFeed line terminators. The /N and /O options specify the same locations within the file, but the /N option counts the number of lines, whereas the /O option counts the number of bytes. The /N option is 1 based, the /O option is 0 based. So the results given by the Carlos and Foxidrive examples are corect/not bugged. Dave Benham
|
| 28 Nov 2012 06:53 |
|
 |
|
dbenham
Expert
Joined: 12 Feb 2011 21:02 Posts: 889 Location: United States (east coast)
|
 Re: Undocumented FINDSTR features and limitations
I've updated my SO post to clarify the /O option; SO FINDSTR post wrote: lineOffset: = The decimal byte offset of the start of the matching line, with 0 representing the 1st character of the 1st line. Only printed if /O option is specified. This is not the offset of the match within the line. It is the number of bytes from the beginning of the file to the beginning of the line.
Dave Benham
|
| 28 Nov 2012 08:52 |
|
 |
|
foxidrive
Joined: 10 Feb 2012 02:20 Posts: 2484
|
 Re: Undocumented FINDSTR features and limitations
dbenham wrote: I've updated my SO post to clarify the /O option; SO FINDSTR post wrote: lineOffset: = The decimal byte offset of the start of the matching line, with 0 representing the 1st character of the 1st line. Only printed if /O option is specified. This is not the offset of the match within the line. It is the number of bytes from the beginning of the file to the beginning of the line.
Dave Benham Thanks Dave. That could be used to count the length of a line also, or several lines. It was very confusing as you normally think of the character offset to be to a match of the regexp/literal. The description should say "prints file offset before each matching line." /O Prints character offset before each matching line.
|
| 28 Nov 2012 11:08 |
|
 |
|
dbenham
Expert
Joined: 12 Feb 2011 21:02 Posts: 889 Location: United States (east coast)
|
 Re: Undocumented FINDSTR features and limitations
foxidrive wrote: That could be used to count the length of a line also, or several lines.
Cool idea foxidrive  Code: @echo off setlocal set "test=Hello world!"
:: Echo the length of TEST call :strLen test
:: Store the length of TEST in LEN call :strLen test len echo len=%len% exit /b
:strLen strVar [rtnVar] setlocal disableDelayedExpansion set len=0 if defined %~1 for /f "delims=:" %%N in ( '"(cmd /v:on /c echo !%~1!&echo()|findstr /o ^^"' ) do set /a "len=%%N-3" endlocal & if "%~2" neq "" (set %~2=%len%) else echo %len% exit /b
I haven't figured out why I must subtract 3 instead of 2, but it appears to work. Dave Benam
|
| 28 Nov 2012 13:12 |
|
|