Windows 批處理腳本:Findstr 輸出:過濾子字符串 (Windows batch script : Findstr output : Filter substring)


問題描述

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 jhaGerhardCompo)

參考文件

  1. Windows batch script : Findstr output : Filter substring (CC BY‑SA 2.5/3.0/4.0)

#batch-file #Windows






相關問題

如何在 Windows 批處理腳本或 Perl 中將文件移動到回收站? (How can I move files to the Recycle Bin in a Windows batch script or Perl?)

psftp 批處理腳本不起作用 (psftp batch script won't work)

用於確定 Windows 和 Office 版本的快速命令或批處理腳本 (quick command or batch script to determine Windows and Office version)

查找 pdfs/doc/docx/etc 的批處理文件 (Batch file to look for pdfs/doc/docx/etc)

批處理文件“and if”語句 (Batch-file "and if" statement)

打開具有特定顏色和標題的 CMD (Open CMD with specific color and title)

使用 excel 2010 更新批處理文件中的變量 (use excel 2010 to update variables in batch file)

讓這批列出文件名,其路徑為文件 gtr 超過一定大小。如何修改以僅列出沒有路徑和擴展名的文件名? (Got this batch to list filenames with path for files gtr than some size.. How to modify to list only filenames without path and extension?)

從變量中刪除括號(CLI-Windows) (Remove Brackets from Variable (CLI-Windows))

僅在不到一天的文件中搜索字符串 (Search for a string only in files less than a day old)

如何從批處理文件本身中找到已編譯的 bat (.exe) 目錄? (How can you find a compiled bat (.exe) directory from within the batch file itself?)

Windows 批處理腳本:Findstr 輸出:過濾子字符串 (Windows batch script : Findstr output : Filter substring)







留言討論