windows - CMD-Batch line length. Possible to remove? If not, how to check for too long lines? -
still new cmd batch scripting...
i've got batch remove tab characters file. works great code:
setlocal disabledelayedexpansion /f "delims=" %%a in ('"findstr /n ^^ %filename%"') ( set "line=%%a" setlocal enabledelayedexpansion set "line=!line:*:=!" if defined line ( set "line=!line: =!" (echo(!line!)>>%tempfile% ) else echo( endlocal )
but didn't delete tab character, whole line! figuered out must have unusual length of line (>9500 characters). if split line manually, works usual.
right i'm looking way either
- make code above work line lenght or
- insert check lines long process, batch can stop process , display appropiate message.
the problem long lines in batch files environment variables can store maximum of 8 kb. however, possible process longer lines in smaller chunks because when set /p
command read long line, reads 1022 characters , remaining characters read next set /p
command. batch file below use method (combined findstr /o "^"
allows know length of lines) copy file lines of unlimited size:
@echo off setlocal enabledelayedexpansion set "last=1022" < input.txt ( /f "delims=:" %%a in ('findstr /o "^" input.txt') ( set /a "len=%%a-last-2, last=%%a, chunks=(len-1)/1022+1" set "chunk=" /l %%i in (1,1,!chunks!) ( set /p "chunk=" set /p "=!chunk!" < nul ) if !chunks! gtr 0 echo/ ) %%a in (input.txt) set /a "len=%%~za-last-2, chunks=(len-1)/1022+1" set "chunk=" /l %%i in (1,1,!chunks!) ( set /p "chunk=" set /p "=!chunk!" < nul ) echo/ ) > output.txt move /y output.txt input.txt
this method requires input lines ends in cr+lf characters (windows standard) , have problems inherent set /p
: may eliminate control characters end of line or end of each chunk of 1022 characters, or spaces beginning of line/chunk; further details @ this post. may modify program changing set /p "=!chunk!" < nul
corresponding set /p "=!chunk: =!" < nul
1 in order eliminate tab characters.
Comments
Post a Comment