0

I want to capture the 2nd word( i.e. the date) from the 2nd line from the below output of a command(let it be xyz)

Data source CODA enabled.
=== 03/13/19 01:45:00 PM
Instance : 0
GBL_COLLECTOR : Nums 12.02.008
GBL_INTERVAL : 299

I am using the below syntax, but getting error.

For /f “tokens=2” %a in (‘xyz | findstr == ‘) do echo %a

Can anyone help me find the exact syntax to capture the date in the 2nd line ?

aschipfl
  • 33,626
  • 12
  • 54
  • 99

1 Answers1

0

Based upon the provided information, I would suggest:

Set "_=1"&For /F "Skip=1Tokens=2" %A In ('xyz 2^>Nul')Do @If Defined _ Echo(%A&Set "_="

The example you gave, which was answered by Squashman in his comment, requires removal of all 'smart quotes' and an escape of the pipe character, |, with a caret, ^:

For /F Tokens^=2 %A In ('xyz 2^>Nul^|Find "=="')Do @Echo %A

Or alternatively, protecting with doublequotes:

For /F "Tokens=2" %A In ('"xyz 2>Nul|Find "==""')Do @Echo %A
Compo
  • 36,585
  • 5
  • 27
  • 39