gonzalloe
gonzalloe

Reputation: 313

How to get values from text file and store it as a variable in batch script?

How can I get the specific value from text file and store it at a variable by using batch scripting?

Eg. (input.txt)

    ============================================================
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    ============================================================
    True
    True
    0000: 56 43 54 23 34 25 33 34  30 30 36 35 30 34 43 60  VRWTF4534024810
    0010: 20 20 20 20 FF FF FF FF  FF FF FF FF FF FF FF FF      ............
    0020: FF FF FF FF FF FF FF FF  FF FF FF FF FF FF FF FF  ................

Any ideas to get "VRWTF4534024810" from the sample text file?

***I am using Windows 10 64-bits OS

Thanks in advance.

Upvotes: 0

Views: 3374

Answers (2)

gonzalloe
gonzalloe

Reputation: 313

I guess this will give a better understanding for tokens and delims. :) https://www.computing.net/howtos/show/batch-files-tokens-and-delimiters-for-loops/473.html

Upvotes: 0

Nahuel Fouilleul
Nahuel Fouilleul

Reputation: 19315

In command line

for /f "tokens=1-26" %a in ('findstr 0000: input.txt') do @echo %r & set var=%r

or in script (double percent)

for /f "tokens=1-26" %%a in ('findstr 0000: input.txt') do @echo %%r & set var=%%r

Upvotes: 1

Related Questions