問題描述
Windows 批處理腳本:Findstr 輸出:過濾子字符串 (Windows batch script : Findstr output : Filter substring)
我有一個腳本:
C:\"Program Files (x86)"\Dell\"Command Configure"\X86_64\cctk advsm ‑‑report=All | findstr /c:"Current speed" >> %LOG_FILE_NAME%
給出以下輸出:
Current speed : 3101 rpm
我只需要實際值“3101” 不是整條線。我怎樣才能得到這個?
參考解法
方法 1:
for
loops are used for this:
for /f "tokens=3* delims=: " %%i in ('"%programfiles(x86)%\Dell\Command Configure\X86_64\cctk" advsm ‑‑report=All ^| findstr "Current speed"') do (echo %%i)>>%LOG_FILE_NAME%
方法 2:
Untested idea, but perhaps it would be simpler still if you just report the value you want in the first place!
@For /F "Tokens=4" %%G In ('^""%ProgramFiles(x86)%\Dell\Command Configure\x86_64\cctk.exe" Advsm ‑‑Report^=C^"') Do >>"%LOG_FILE_NAME%" @Echo %%G
If C
doesn't output what you want then you'd have to use Report=All and search for your line. You can use find.exe for that:
@For /F "Tokens=4" %%G In ('^""%ProgramFiles(x86)%\Dell\Command Configure\x86_64\cctk.exe" Advsm ‑‑Report^=All ^| %SystemRoot%\System32\find.exe "Current speed"^"') Do >>"%LOG_FILE_NAME%" @Echo %%G
(by vibhash jha、Gerhard、Compo)