Windows findstr 用法與範例

本篇 ShengYu 介紹 Windows findstr 搜尋字串指令,findstr 通常用來搭配其它指令來搜尋字串,例如 findstr 搭配 cat 來搜尋檔案裡的特定字串,findstr 算是 Windows DOS 必學指令,學會這招讓工作更快速輕鬆。

findstr 搜尋特定字串

Windows 基本的 findstr 搜尋特定字串用法如下,假設我要在 xxx.txt 檔案裡搜尋 pattern 字串,

1
cat xxx.txt | findstr "pattern"

findstr 搜尋多個字串

findstr 要搜尋多個字串的話,可以用空格隔開,例如 findstr 搜尋兩個字串的話就這樣寫,

1
cat xxx.txt | findstr "pattern1 pattern2"

findstr 搜尋三個字串的話就這樣寫,

1
cat xxx.txt | findstr "pattern1 pattern2 pattern2"

以上就是 Windows findstr 用法與範例介紹,
如果你覺得我的文章寫得不錯、對你有幫助的話記得 Facebook 按讚支持一下!