
Regards
aGerman
Moderator: DosItHelp
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>.![]()
![]()
Code: Select all
echo.#|Findstr "."
Code: Select all
echo.#|Findstr /L "."
Code: Select all
echo #|findstr ". a"
Code: Select all
echo #|findstr "a ."
Code: Select all
C:\Users\Carlos>echo.#|findstr /c /l "#"
FINDSTR: se ha omitido /c
#
C:\Users\Carlos>echo.#|findstr /c /r "#"
FINDSTR: se ha omitido /c
#
Code: Select all
all#everybody#is#ok
Code: Select all
findstr /N /O "#" file.txt
Code: Select all
1:0:all#everybody#is#ok
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.
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.
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
foxidrive wrote:That could be used to count the length of a line also, or several lines.
Code: Select all
@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
Code: Select all
squash, 22, 14, 15, 12, 18, 19
squashman,22,14,15,12,18,19
josh,10, 16, 19, 3, 5, 19, 18, 7, 2, 4
joshua,10, 16, 19, 3, 5, 19, 18, 7, 2, 4
Code: Select all
@echo off
set "userid=squash"
set "number=15"
echo match whole word userid
findstr "\<%userid%\>" "wholetest.txt"
echo match whole word number
findstr "\<%number%\>" "wholetest.txt"
echo match two whole words
findstr "\<%userid%\>.*\<%number%\>" "wholetest.txt"
pause
goto :EOF
Code: Select all
match whole word userid
squash, 22, 14, 15, 12, 18, 19
match whole word number
squash, 22, 14, 15, 12, 18, 19
squashman,22,14,15,12,18,19
match two whole words
Code: Select all
squash, 22, 14, 15, 12, 18, 19
dbenham on StackOverflow wrote: Regex word boundary
\< must be the very first term in the regex. The regex will not match anything if any other characters precede it. \< corresponds to either the very beginning of the input, the beginning of a line (the position immediately following a <LF>), or the position immediately following any "non-word" character. The next character need not be a "word" character.
\> must be the very last term in the regex. The regex will not match anything if any other characters follow it. \> corresponds to either the end of input, the position immediately prior to a <CR>, or the position immediately preceding any "non-word" character. The preceding character need not be a "word" character.