[燈火闌珊] 關於cmd命令里的findstr匹配多個關鍵詞


no

raining now

go to school and play with code 你.

 

findstr "\<go  code\>"

這樣就能匹配輸出包含go到code的文本了

看起來丑,其實也就是\斜線加尖括號   (轉義而已)

echo "go to school and play with code 你." | findstr "\<go code\>"
結果: "go to school and play with code 你."

但是這樣也行,我就懵了

echo "go to school and play with code 你." | findstr "\<code go\>"
"go to school and play with code 你."

 還有這樣

echo "go to school and play with code 你." | findstr "\<code\> \<go\>"
"go to school and play with code 你."

而這最后這種情況有個強大的bug,

它有時搭配dir時只輸出包含中文的內容,我的是win10預覽版,正式版怎么樣不清楚,氣死我了,難怪windows在命令行領域干不過Linux

出bug的命令[一臉懵逼]

 

 

所以這玩意到底是怎么用的

 

附上從不知道哪里復制過來的,侵權請聯系我

利用元字符查找。
\<xyz    字位置: 字的開始
xyz\>    字位置: 字的結束
  1. @echo off
  2. findstr "\<1080\> \<443\> \<80\>" 1.txt>>2.txt
  3. echo 處理完成,按任意鍵退出
  4. pause>nul


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM