There will be only one taskId but I am getting this is multiple lines.
I want to retrive the taskId which is same for a flow.
you have only one taskId, but you have two lines in the text file, which means, your loop is executed two times. And as taskid
isn't overwritten the second time, it still holds the value from the first time.
Change ... in ('type abc.txt') do ...
to ... in ('type abc.txt^|find "taskId="') do ...
to filter abc.txt
to the relevant line only.
Also, you do echo !taskID! >> def.txt
, which adds two trailing spaces. I slightly changed the redirection syntax to avoid that.
That changes your complete code to:
@echo off
SetLocal EnableDelayedExpansion
for /f "tokens=2 delims=:," %%i in ('type abc.txt^|find "taskId=') do (
@set%%i
REM To remove Space into Variable
Set "taskID=!taskID: =!"
>>def.txt echo !taskID!
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…