How can I get unique records from in the below case

前端 未结 1 1565
青春惊慌失措
青春惊慌失措 2020-12-12 08:09

I am trying to run a script where I am trying to find a value from a file. File is :

8009 [main] INFO  com.utilities.task.ICSTask  - Submitted run of the tas         


        
相关标签:
1条回答
  • 2020-12-12 08:36

    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!
    )
    
    0 讨论(0)
提交回复
热议问题