What are the undocumented features and limitations of the Windows FINDSTR command?

后端 未结 8 1733
耶瑟儿~
耶瑟儿~ 2020-11-21 04:23

The Windows FINDSTR command is horribly documented. There is very basic command line help available through FINDSTR /?, or HELP FINDSTR, but it is

8条回答
  •  旧时难觅i
    2020-11-21 05:04

    I'd like to report a bug regarding the section Source of data to search in the first answer when using en dash (–) or em dash (—) within the filename.

    More specifically, if you are about to use the first option - filenames specified as arguments, the file won't be found. As soon as you use either option 2 - stdin via redirection or 3 - data stream from a pipe, findstr will find the file.

    For example, this simple batch script:

    echo off
    chcp 1250 > nul
    set INTEXTFILE1=filename with – dash.txt
    set INTEXTFILE2=filename with — dash.txt
    
    rem 3 way of findstr use with en dashed filename
    echo.
    echo Filename with en dash:
    echo.
    echo 1. As argument
    findstr . "%INTEXTFILE1%"
    echo.
    echo 2. As stdin via redirection
    findstr . < "%INTEXTFILE1%"
    echo.
    echo 3. As datastream from a pipe
    type "%INTEXTFILE1%" | findstr .
    echo.
    echo.
    rem The same set of operations with em dashed filename
    echo Filename with em dash:
    echo.
    echo 1. As argument
    findstr . "%INTEXTFILE2%"
    echo.
    echo 2. As stdin via redirection
    findstr . < "%INTEXTFILE2%"
    echo.
    echo 3. As datastream from a pipe
    type "%INTEXTFILE2%" | findstr .
    echo.
    
    pause
    

    will print:

    Filename with en dash:

    1. As argument
      FINDSTR: Cannot open filename with - dash.txt

    2. As stdin via redirection
      I am the file with an en dash.

    3. As datastream from a pipe
      I am the file with an en dash.

    Filename with em dash:

    1. As argument
      FINDSTR: Cannot open filename with - dash.txt

    2. As stdin via redirection
      I am the file with an em dash.

    3. As datastream from a pipe
      I am the file with an em dash.

    Hope it helps.

    M.

提交回复
热议问题