| 1. |
Solve : Need Help extracting specific data from a txt file and using it is cmd argument? |
|
Answer» All, Number - 12345This data is in a txt file that is created by another program. Basically the upgrade itself will create this text file. Use tokens 1* with the dash as the delimiter, for each line, and use the * token for your fields, all except the last (hint: it starts "Timestamp") where you do another for /f on the second token, using 1* with the space as the delimiter, and take the first token. (1) input.txt Number - 12345 Version - 1.02.03.4567 Name - Software name Status - Upgrade completed successfully Message - success Timestamp - 2019-12-11 17:12:45.188 (2) batch script echo off set filename=input.txt for /f "tokens=1-2* delims= " %%A in (' type "%filename%" ^| find "Number" ') do set number=%%C for /f "tokens=1-2* delims= " %%A in (' type "%filename%" ^| find "Version" ') do set version=%%C for /f "tokens=1-2* delims= " %%A in (' type "%filename%" ^| find "Name" ') do set name=%%C for /f "tokens=1-2* delims= " %%A in (' type "%filename%" ^| find "Status" ') do set status=%%C for /f "tokens=1-2* delims= " %%A in (' type "%filename%" ^| find "Message" ') do set message=%%C for /f "tokens=1-3 delims= " %%A in (' type "%filename%" ^| find "Timestamp" ') do set mydate=%%C echo number: %number% echo version: %version% echo name: %name% echo status: %status% echo message: %message% echo mydate: %mydate% (3) script output number: 12345 version: 1.02.03.4567 name: Software name status: Upgrade completed successfully message: success mydate: 2019-12-11thank you. This worked perfectly. |
|