Hi,
I am trying to write an automatic batch file that will extract 3 lines after a certain string.
For example I have the a text file with the following information in it (this is just a portion of the text file),
Forecast for the rest of Sunday 3 June
Cloudy. Patchy morning fog. Isolated showers becoming scattered this afternoon.
Winds southeasterly and light tending east to southeasterly up to 25 km/h
during the morning.
City Centre A few showers. Max 15
Chance of any rainfall: 70%
Rainfall: 2 to 4 mm
Around Melbourne
Geelong Max 15 Watsonia Max 14
Laverton Max 15 Mount Dandenong Max 10
Tullamarine Max 14 Yarra Glen Max 14
Scoresby Max 14 Frankston Max 14
No UV Alert, UV Index predicted to reach 2 [Low]
Forecast for Monday 4 June
Cloudy. Scattered showers. Winds south to southeasterly up to 35 km/h.
City Centre A few showers. Min 10 Max 14
Forecast for Tuesday 5 June
Partly cloudy. Isolated showers clearing during the afternoon. Winds south to
southeasterly up to 30 km/h.
City Centre Shower or two clearing. Min 10 Max 14
I want to run a batch file that will extract all information between the first ‘City Centre’ and ‘Around Melbourne’ into a new txt file. So in this example the new text file should read,
A few showers. Max 15
Chance of any rainfall: 70%
Rainfall: 2 to 4 mm
The problem is ‘City Centre’ appears multiple times in the original text file, I only want to grab information from the first ‘City Centre’ and end at ‘Around Melbourne’.
Any help would be much appreciated.
::
:: che.bat Sun 03-06-2012 13:13:54.10
@echo off > newfile & setLocal enableDELAYedeXpansioN
set C=
set A=
for /f “tokens=1* delims=[]” %%a in (‘find /v /n “” ^< weather’) do (
echo.%%b|find “City Centre” > nul && if not defined C set C=%%a
echo.%%b|find “Around Melbourne” > nul && if not defined A set A=%%a
)
for /f “tokens=1* delims=[]” %%a in (‘find /v /n “” ^< weather’) do (
if %%a equ !C! (
set S=%%b
set S=!S:City Centre=!
>> newfile echo.!S!
)
if %%a gtr !C! if %%a lss !A! >> newfile echo.%%b
)
goto :eof
::====== script ends here =================
=====================================
Life is too important to be taken seriously.
M2