Search code examples
batch-filevariablestext-filesfindstr

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.


Solution

  • 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