|
Posted by Timo Salmi on 10/09/06 07:27
batman <uspensky@gmail.com> wrote:
> i have a text file that is like:
>
> date = OCT0606
> asdf
> sdaf
> asdfasdgsdgh
> asdfsdfasdg
> START-OF-DATA
> asdfasdfg
> asdfgdfgsfg
> sadfsdfgsa
> asdfgsdfg
> END-OF-DATA
> asdfgalsdkdfklmlkm
> asdfgasdfg
>
> i need to clear everything from this file except the data between the
> START-OF-DATA and END-OF-DATA using a batcj file...
(alt.msdos.batch.nt added and followups redirected)
@echo off & setlocal enableextensions enabledelayedexpansion
set source=C:\_M\MyData.txt
set flagStart=
set flagEnd=
for /f %%a in ('type "%source%"') do (
echo %%a|find "START-OF-DATA">nul
if !errorlevel! EQU 0 set flagStart=true
echo %%a|find "END-OF-DATA">nul
if !errorlevel! EQU 0 set flagEnd=true
if defined flagStart if not defined FlagEnd (
echo %%a|find /v "START-OF-DATA"
)
)
endlocal & goto :EOF
The output
C:\_D\TEST>cmdfaq
asdfasdfg
asdfgdfgsfg
sadfsdfgsa
asdfgsdfg
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
Navigation:
[Reply to this message]
|