Solved How to extract specific text from file into batch variable

January 23, 2018 at 09:27:41
Specs: Windows 7

I am receiving a daily text file (example) from
--- snip ---
:Product: Geophysical Alert Message wwv.txt
:Issued: 2018 Jan 23 1505 UTC
# Prepared by the US Dept. of Commerce, NOAA, Space Weather Prediction Center
# Geophysical Alert Message
Solar-terrestrial indices for 22 January follow.
Solar flux 70 and estimated planetary A-index 12.
The estimated planetary K-index at 1500 UTC on 23 January was 1.

No space weather storms were observed for the past 24 hours.

No space weather storms are predicted for the next 24 hours.
--- snip ---

The numeric values can vary, but the content of the text file is fixed.
Out of this file I need the following result in a variable "Solar flux 70, A-index 12, K-index 1, No space weather storm"

Any help is appreciated

See More: How to extract specific text from file into batch variable

Report •

January 23, 2018 at 20:20:32
✔ Best Answer
@echo off & setlocal
@echo off & setlocal
:: set the inputfilename here
set geospace=geospace

for /f "tokens=1-3,7-8" %%a in ('find "Solar flux"^<%geospace%') do set k=%%a %%b %%c,%%d %%~ne,
echo stage1: %k%
for /f "tokens=4,12" %%a in ('find "K-index"^<%geospace%') do set k=%k% %%a %%~nb
echo stage2: %k%
for /f "tokens=1-5" %%a in ('find "No space weather storms are"^<%geospace%') do set k=%k%,%%a %%b %%c %%d
echo final: %k%
::-------------- end script
obviously I assumed you wanted "are" and not "were" regarding the space storms clause....

message edited by nbrane

Report •

January 23, 2018 at 23:31:06
nbrane - Thanks - You made my day!

Report •
Related Solutions

Ask Question