Get specific string from a text file using batch command [closed]

对着背影说爱祢 提交于 2020-01-17 15:16:07

问题


I am looking for a Windows batch script command that can extract specific data string from an automatically generated text file. Note that the first line in the test.txt file is always empty. I need to extract only "2017/01/01-01" (from the 2nd line) to a different file. Findstr itself cannot be used as that will always extract whole line, not only the selected string.

Example test.txt file content:

<empty line>
    DateID : 2017/01/01-01     
        texttextext
        texttextext
        ...

Thanks in advance.


回答1:


gets the first occurrence of DateID ::

for /f "tokens=2 delims=:" %%a in ('type test.txt^|find "DateID : "') do (
  set dateid=%%a & goto :continue
)
:continue
set dateid=%dateid:~1%
echo %dateid%


来源:https://stackoverflow.com/questions/42243585/get-specific-string-from-a-text-file-using-batch-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!