parsing file and shortening selected lines
Posted: 22 Aug 2014 09:00
i use Dostip's BatchSubstitute.bat to change text in selected lines ( it searches for the old text ) of a file.
that works fine.
what i want to do now is instead of substituting a new expression for the old text is to eliminate the old text and shorten that line of the file down to the first 25 letters.
Unfortunately I do not understand enough of how BatchListOfFiles.bat works to do that.
Help would be appreciated.
The text of BatchSubstitute.bat:
@echo off
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
:: OldStr [in] - string to be replaced
:: NewStr [in] - string to replace with
:: File [in] - file to be parsed
:$changed 20100115
:$source http://www.dostips.com
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
that works fine.
what i want to do now is instead of substituting a new expression for the old text is to eliminate the old text and shorten that line of the file down to the first 25 letters.
Unfortunately I do not understand enough of how BatchListOfFiles.bat works to do that.
Help would be appreciated.
The text of BatchSubstitute.bat:
@echo off
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
:: OldStr [in] - string to be replaced
:: NewStr [in] - string to replace with
:: File [in] - file to be parsed
:$changed 20100115
:$source http://www.dostips.com
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)