user2052447
user2052447

Reputation: 1

Batch File..Get a Character from multiple lines of text

I have this text in a .txt file

Job Status  : RUN OK (1)
Job Controller  : not available
Job Start Time  : Thu Feb 07 15:13:47 2013
Job Wave Number : 4
User Status : not available
Job Control : 0
Interim Status  : NOT RUNNING (99)
Invocation ID   : not available
Last Run Time   : Thu Feb 07 15:13:53 2013
Job Process ID  : 0
Invocation List : Param_Test_Job
Job Restartable : 0

Is there a way where by I can get the number 1 (after RUN OK) between the () in line 1 to use conditional logic downstream. I am trying to achieve this in a batch file.

(This number will always be in the first line and the text "Job Status" will always be there too)

Thanks for your help

Upvotes: 0

Views: 148

Answers (1)

dbenham
dbenham

Reputation: 130819

This will work no matter which line Job Status appears. If Job Status appears more than once, it will take the value from the last appearance.

@echo off
for /f "tokens=2 delims=()" %%N in (
  'findstr /bc:"Job Status" test.txt'
) do set "result=%%N"

Upvotes: 2

Related Questions