在以下情况下如何获取唯一记录 [英] How can I get unique records from in the below case
问题描述
我正在尝试运行脚本,试图从文件中查找值. 文件是:
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 task: taskId=0015FL0Z0000000000R6, taskRunId=20789
https://use4.dm-us.com/saas/api/v2/activity/activityLog?taskId=0015FL0Z0000000000R6&runId=20789
我写的代码是:
SetLocal EnableDelayedExpansion
@for /f "tokens=2 delims=:," %%i in ('type abc.txt') do (
@set%%i
REM To remove Space into Variable
Set "taskID=!taskID: =!"
echo !taskID! >> def.txt
)
我得到的结果是:
0015FL0Z0000000000R6
0015FL0Z0000000000R6
0015FL0Z0000000000R6
0015FL0Z0000000000R6
因此,我想在def.txt
文件中获得0015FL0Z0000000000R6
的唯一值.我该如何实现?
I want to get unique value of 0015FL0Z0000000000R6
in def.txt
file as a result. How can I achieve this?
推荐答案
只有一个taskId,但我得到的是多行. 我想检索与流程相同的taskId.
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.
您只有一个taskId,但是在文本文件中有两行,这意味着您的循环执行了两次.而且由于taskid
不会第二次被覆盖,因此它仍然保留第一次的值.
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.
将... in ('type abc.txt') do ...
更改为... in ('type abc.txt^|find "taskId="') do ...
,仅将abc.txt
过滤到相关行.
Change ... in ('type abc.txt') do ...
to ... in ('type abc.txt^|find "taskId="') do ...
to filter abc.txt
to the relevant line only.
此外,您执行echo !taskID! >> def.txt
,这将添加两个尾随空格.为了避免这种情况,我稍微更改了重定向语法.
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!
)
这篇关于在以下情况下如何获取唯一记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!