I am new to batch script, and I am trying to parse a file that has key value (kind) of pairs delimited by new line. For example:
the value of abc
1234
the value of def
5678
the value of ghi
9876
I would like to read this file using new line as delimited so that I can access the values.
Something like
for /f "tokens=1,2,3 delims='\n'" %%i in ('findstr /C:the value of abc 'filepath') do echo %%j
should do the job, if you require each token from two successive lines to be output. Would be much easier if we had a listing of the required output rather than having to guess from code that doesn't work.
Essentially, this code saves the contents of one line then detects that the second has been read by the fact that the variable holding the previous line is defined. Under those circumstances,
for/f
is used to tokenise the concatenation of the two lines.You can't set 'new line' as delimiter. Try this:
What do you think of that? In powershell:
It displays the next line after the pattern.
I just put it here as an option:
Not sure what you're going to do with those Name/Value pairs after you get them, but if you're going to do it in Powershell, do it right and start by creating objects:
I normally use the given batch command, to read each line in file
Here,
"delim="
does the trick.