0

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.

Jack Payne
  • 49
  • 1
  • 1
  • 6

1 Answers1

5

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%
Stephan
  • 53,940
  • 10
  • 58
  • 91