问题
I have a text file with a string occurs multiple lines. I want to get the line where this is the first occurrence of the string. I could find all occurrences using below command but I want only first occurrence in single line command.
findstr /C:"taskId" Book.txt
Book.txt
3047 [main] INFO com.informatica.saas.utilities.task.ICSTask -
Submitted run of the task: taskId=0015FL0Z0000000000R6,
taskRunId=20869
https://use4.dm-us.informaticacloud.com/saas/api/v2/activity/activityMonitor
https://use4.dm-us.informaticacloud.com/saas/api/v2/activity/activityMonitor
https://use4.dm-us.informaticacloud.com/saas/api/v2/activity/activityLog?taskId=0015FL0Z0000000000R6&runId=20869
回答1:
Try something like this:
for /f "delims=" %%a in ('findstr /C:"taskId" Book.txt') do (
echo %%a
goto :continue
)
:continue
来源:https://stackoverflow.com/questions/59062749/batch-scripting-find-the-first-occurence-of-string-taskid