Notepad content deletion up to some kb

December 16, 2009 at 19:43:19
Specs: Windows XP
i am using the batch for delete first 6 line and copy in to another .txt file as backup.

@echo off > 2.txt
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (1.txt) do (
set /a N+=1
if !N! leq 6 echo %%a >> 2.txt
if !N! gtr 6 echo %%a >> #

copy # 1.txt > nul
del #

it works good but i want the execution happened only for some kb. meaning if 1.txt is having 200 kbs of datas, then the batch file will delete the first 6 lines up to the file memory reaches 40 kbs. After that the particular batch will stop deleting the first 6 line. when the files size increases more that 40 kbs it will happened automatically again. pls help.........

See More: Notepad content deletion up to some kb

Report •

December 17, 2009 at 08:52:34
Maybe it's a limit imposed by the FOR command, to read lines of a batchfile.

In theory you can have a 5 megabyte textfile, with all text on 1 line ... maybe that is the type of problem you are facing.

Just as info, but Unix has got some nice commands for that, and they are ported to MS as well. Look for "tail" or "head". You give up compatibility, but you win features ...

Report •

December 17, 2009 at 12:16:28
I don't like it; I suspect something else is going on here, but let's cover our bases. How many lines are in the input file? If it's more than 2^31 - 1 (or 2147483647) lines, that script will break.

Report •

December 17, 2009 at 17:21:12
tvc: i think you might have misunderstood op, either that or i misunderstood and you are right:
*After that the particular batch will stop deleting the first 6 line.*
i think what he means is not that the batchfile is failing after 40k, but that he wants it to stop when the main file is downsized to 40k.
to op: i'm not sure what you want to do with the 6-line chunks.
just keep the first one? just keep the last one extracted?
or keep them all? maybe you can modify my code to do what you want with them. as for monitoring the file continuously, you can make this program loop or set up a recurring task (using AT, if you have it functional) if you just need to check it on a periodic basis.
here is my offering:

@echo off > temp && setlocal enabledelayedexpansion
set /a uu=1
set /a nn=0
set /a mm=0
set /a downsize=40000
for /d %%a in (xxx) do set xxsz=%%~za
if !xxsz! leq !downsize! goto :exx
echo 1 -------------- > sixes
set newsize=!xxsz!
for /f %%b in (xxx) do (
set /a nn+=1
echo %%b >> sixes
echo %%b >> temp
if !nn! geq 6 call :abce
if !newsize! leq !downsize! goto :end
goto :exx

set /a mm+=1
set /a nn=0
for /d %%a in (temp) do set cc=%%~za
move /y temp lastsix
if !mm! equ 1 move /y temp frstsix
set /a qq=!mm!+1
echo !qq!-------------- >> sixes
set /a newsize-=!cc!
echo off>temp
goto :exx
set /a mm*=6
del newxxx 2>nul
for /f "skip=%mm% tokens=* delims=" %%a in (xxx) do echo %%a >> newxxx
move /y newxxx xxx

Report •

Related Solutions

December 18, 2009 at 15:58:16
LOL As ever a solution starts with a clear problem statement.

Helping others achieve escape felicity


Report •

Ask Question