findstr
外觀
| 其他名稱 | qgrep |
|---|---|
| 開發者 | Microsoft, ReactOS貢獻者 |
| 作業系統 | Windows, ReactOS |
| 平台 | 跨平台 |
| 類型 | 命令 |
| 許可協議 | Windows: 專有軟件 商業軟件 ReactOS: GNU通用公共許可證 |
| 網站 | docs |
findstr是Microsoft Windows[1][2]與ReactOS[3]命令行(即殼層)下用於在特定文件中搜索特定字符串的命令。[4]
概覽
[編輯]此命令將指定行發送到標準輸出設備。[5]
它與find命令相似。然而,find命令支持UTF-16,而findstr不支持。另一方面,findstr支持正則表達式,但find不支持。
findstr最早在Windows 2000 Resource Kit下以名稱qgrep發行。[6]
findstr無法搜索到Unicode文件中常見的空字符。[7]
語法
[編輯]FINDSTR flags strings [drive:][path]filename[...]
參數:
flags下列選項的任意組合。strings搜索目標文本。[drive:][path]filename指定被搜索文件。
選項:
/B匹配一行的開頭。/E匹配一行的結尾。/L按原字符串搜索。/R按正則表達式搜索。/S在當前目錄及所有子目錄下搜索匹配文件。/I不區分大小寫。/X輸出嚴格匹配的行。/V僅輸出不匹配的行。/N在所有匹配行前輸出行號。/M僅當文件有至少一處匹配時輸出文件名。/O在所有匹配行前輸出字符偏移量。/P跳過含有不可打印字符的文件。/OFF[LINE]不要跳過有「離線」屬性組的文件。/A:attr用兩位十六進制數指定顏色屬性(詳見"color /?")。/F:file從指定文件獲取被搜索文件(/ 表示直接讀取自控制台)。/C:string將指定字符串按照原字符串搜索。/G:file從指定文件獲取搜索目標文本(/ 表示直接讀取自控制台)。/D:dir在半角冒號指定的目錄列表下搜索。
注意: 下列命令顯示此命令的詳細幫助:
FINDSTR /?
示例
[編輯]將正在運行的服務保存到「_services.txt」文件,然後搜索文件中包含"network"的行(不區分大小寫):
@echo off
set searchstr=network
net start>_services.txt
FINDSTR /I "%searchstr%" _services.txt
pause
輸出是:
Network Connections Network List Service Network Location Awareness Network Store Interface Service Windows Media Player Network Sharing Service Press any key to continue . . .
另請參閱
[編輯]維基教科書中的相關電子教學:Guide to Windows Commands
參考資料
[編輯]- ^ Microsoft WinXP documentation for findstr. [2021-06-11]. (原始內容存檔於2018-02-03).
- ^ Microsoft Server 2012/2016 documentation for findstr. [2021-06-11]. (原始內容存檔於2021-05-28).
- ^ https://github.com/reactos/reactos/blob/master/base/applications/findstr/findstr.c
- ^ MS-DOS and Windows command line findstr command. [2021-06-11]. (原始內容存檔於2021-06-11).
- ^ Excellent documentation on usage of findstr. [2021-06-11]. (原始內容存檔於2021-07-12).
- ^ History of Findstr from Raymond Chen. [2021-06-11]. (原始內容存檔於2015-11-21).
- ^ Findstr - Search for strings - Windows CMD - SS64.com. [2021-06-11]. (原始內容存檔於2021-06-11).
更多
[編輯]- Stanek, William R. Windows Command-Line Administrator's Pocket Consultant, 2nd Edition. Microsoft Press. 2008. ISBN 978-0735622623.
- John Paul Mueller. Windows Administration at the Command Line for Windows Vista, Windows 2003, Windows XP, and Windows 2000. John Wiley & Sons. 2007. ISBN 978-0470165799.