使用批处理命令从文本文件中获取特定的字符串 [英] Get specific string from a text file using batch command

查看:1062
本文介绍了使用批处理命令从文本文件中获取特定的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个Windows批处理脚本命令,该命令可以从自动生成的文本文件中提取特定的数据字符串.请注意,test.txt文件中的第一行始终为空.我只需要将" 2017/01/01-01 "(从第二行)提取到另一个文件中.不能使用Findstr本身,因为它会始终提取整行,而不仅是所选字符串.

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.

test.txt文件内容示例:

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

谢谢.

推荐答案

获取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%

这篇关于使用批处理命令从文本文件中获取特定的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆