Clip4TB-append.txt has like the below
before
*****-----
1
*****-----
2
*****-----
3
*****-----
4
after
*****-----
2
*****-----
3
*****-----
4
1,2,3,4 from the above represent the contents of clipboard made by CTRL-C
i need to make a "CTRL-C" clipboard to save its history
if Clip4TB-append.txt has FOUR *****----- lines or higher, i need a batch that deletes the 1st CTRL-C's content from the txt file and then puts back up the last 3 clipboard contents so that a TXT file could maintain its size by rotation
GetClip-append.bat has
ECHO. >> "C:\ZTREE\F9\Clip4TB-append.txt"
ECHO *****----- >> "C:\ZTREE\F9\Clip4TB-append.txt"
C:\Utility\GetClip.exe >> "C:\ZTREE\F9\Clip4TB-append.txt"
ECHO. >> "C:\ZTREE\F9\Clip4TB-append.txt"
making a "CTRL-C" clipboard TXT file to save its history then pulls UP its contents
Moderator: DosItHelp
Re: making a "CTRL-C" clipboard TXT file to save its history then pulls UP its contents
a trial Clip4TB-append.txt has
*****-----
aaa
*****-----
bbb
*****-----
ccc
*****-----
ddd
*****************************************************
REM my attempt starts from here
@ECHO OFF
SET FS=m:\Clip4TB-append.txt
FOR /F %%V IN ('TYPE "%FS%" ^| FIND /C "*****-----"') DO SET C1=%%V
ECHO.
IF %C1% LSS 4 GOTO :END
IF %C1% GEQ 4 GOTO :Find2ndLine
:Find2ndLine
FOR /F "SKIP=1 Delims=" %%V IN ('TYPE "%FS%" ^| FIND /N "*****-----"') DO (
SET "C2=%%V"
GOTO :break
)
:break
ECHO %C2%
FOR /F "Delims=]" %%V IN ('ECHO %C2%') DO SET S1=%%V
rem S1 is getting the string from the leftside of the delims.... which is natural
FOR /F "Delims=[" %%V IN ('ECHO %S1%') DO SET S2=%%V
rem S2 is getting the string from the RIGHTside of the delims.......
rem why is that? if it finds none from the leftside then it takes it from the right
SET /A C2=S2
SET /A C2=C2-1 &REM from 1 to (5-1)th lines must be deleted
ECHO %C2%
::the script below was given by aGerman long ago...., I modified
::from
::if %%A NEQ %DELETE% echo(!line!
::to
::if %%A GTR %DELETE% echo(!line!
::WOW! it seemed working
::maybe i got this, i hope someone to check if there is any subtlety
@echo off &setlocal
set "file=%FS%"
set /A DELETE=C2
IF /I %DELETE%==0 GOTO :EOF
setlocal EnableDelayedExpansion
<"!file!" >"!file!.~tmp" (
for /f %%i in ('type "!file!"^|find /c /v ""') do for /L %%A in (1 1 %%i) do (
set "line="& set /p "line="
if %%A GTR %DELETE% echo(!line!
)
)
>nul move /y "!file!.~tmp" "!file!"
endlocal
pause
:END
PS: it started as a question. while i was posting it, i was able to actually make it work little by little, so i kept on editing the post, i hope you dont mind me posting it
*****-----
aaa
*****-----
bbb
*****-----
ccc
*****-----
ddd
*****************************************************
REM my attempt starts from here
@ECHO OFF
SET FS=m:\Clip4TB-append.txt
FOR /F %%V IN ('TYPE "%FS%" ^| FIND /C "*****-----"') DO SET C1=%%V
ECHO.
IF %C1% LSS 4 GOTO :END
IF %C1% GEQ 4 GOTO :Find2ndLine
:Find2ndLine
FOR /F "SKIP=1 Delims=" %%V IN ('TYPE "%FS%" ^| FIND /N "*****-----"') DO (
SET "C2=%%V"
GOTO :break
)
:break
ECHO %C2%
FOR /F "Delims=]" %%V IN ('ECHO %C2%') DO SET S1=%%V
rem S1 is getting the string from the leftside of the delims.... which is natural
FOR /F "Delims=[" %%V IN ('ECHO %S1%') DO SET S2=%%V
rem S2 is getting the string from the RIGHTside of the delims.......
rem why is that? if it finds none from the leftside then it takes it from the right
SET /A C2=S2
SET /A C2=C2-1 &REM from 1 to (5-1)th lines must be deleted
ECHO %C2%
::the script below was given by aGerman long ago...., I modified
::from
::if %%A NEQ %DELETE% echo(!line!
::to
::if %%A GTR %DELETE% echo(!line!
::WOW! it seemed working
::maybe i got this, i hope someone to check if there is any subtlety
@echo off &setlocal
set "file=%FS%"
set /A DELETE=C2
IF /I %DELETE%==0 GOTO :EOF
setlocal EnableDelayedExpansion
<"!file!" >"!file!.~tmp" (
for /f %%i in ('type "!file!"^|find /c /v ""') do for /L %%A in (1 1 %%i) do (
set "line="& set /p "line="
if %%A GTR %DELETE% echo(!line!
)
)
>nul move /y "!file!.~tmp" "!file!"
endlocal
pause
:END
PS: it started as a question. while i was posting it, i was able to actually make it work little by little, so i kept on editing the post, i hope you dont mind me posting it