Page 1 of 1
how do i insert 2 lines to many batch files after skipping 1st line?
Posted: 08 Jan 2022 13:27
by nnnmmm
how do i insert 2 lines below to many batch files after skipping 1st line of each batch?
Code: Select all
SET K0="..\GAMEPATH.TXT"
FOR /F "Tokens=*" %%V IN ('TYPE %K0%') DO (SET K1=%%V)
before AA001.bat has
1
2
3
4
5
6
after AA001.bat has
1
SET K0="..\GAMEPATH.TXT"
FOR /F "Tokens=*" %%V IN ('TYPE %K0%') DO (SET K1=%%V)
2
3
4
5
6
Re: how do i insert 2 lines to many batch files after skipping 1st line?
Posted: 08 Jan 2022 14:49
by aGerman
(I'll refrain from giving you the same advices repeatedly...)
You can't insert lines without writing the file new.
Code: Select all
@echo off &setlocal
set "file=AA001.bat"
setlocal EnableDelayedExpansion
<"!file!" >"!file!.~tmp" (
for /f %%i in ('type "!file!"^|find /c /v ""') do (
set "line="& set /p "line="
echo(!line!
echo SET K0="..\GAMEPATH.TXT"
echo FOR /F "Tokens=*" %%%%V IN ('TYPE %%K0%%'^) DO (SET K1=%%%%V^)
for /l %%j in (2 1 %%i) do (
set "line="& set /p "line="
echo(!line!
)
)
)
>nul move /y "!file!.~tmp" "!file!"
endlocal
Steffen
Re: how do i insert 2 lines to many batch files after skipping 1st line?
Posted: 08 Jan 2022 23:39
by Aacini
Code: Select all
@echo off
setlocal EnableDelayedExpansion
for %%f in (*.bat) do (
< "%%f" (
set /P "line1="
echo(!line1!
echo SET K0="..\GAMEPATH.TXT"
echo FOR /F "Tokens=*" %%%%V IN ('TYPE %%K0%%'^) DO (SET K1=%%%%V^)
findstr "^"
) > temp.tmp
move /Y temp.tmp "%%f" > NUL
)
Antonio
Re: how do i insert 2 lines to many batch files after skipping 1st line?
Posted: 09 Jan 2022 03:49
by nnnmmm
zttag - skip insert rest 1.BAT has
Code: Select all
::skip 4 lines, inject 2 lines, do the rest
::if inject more, add echo more.
::works for SKIP=0
::
::echo per 1 - no error for ABC AB!C "AB C" "AB !C" "AB&C" "AB &C" auto-quotes space &
::echo per~1 - no error for ABC AB!C AB C AB !C NO auto-quotes on space
::echo per~1 - error for AB&C AB &C
::echo "=per~1" - no error for ABC AB!C AB C AB !C NO auto-quotes on space
::echo "=per~1" - error for AB&C AB &C
::----------------------------------------------
::but inside setlocal EnableDelayedExpansion
::per 1 - no error for ABC AB!C
::per 1 - error for AB C AB !C AB&C AB &C
::per~1 - no error for ABC AB C AB!C AB !C
::per~1 - error for AB&C AB &C
::
::"=per~1" - no error for ABC AB!C AB C AB !C AB&C AB &C
:: shows error outside, no error inside
REM ****************************************************************
@echo off &setlocal
set "file=%~1"
set /A SKIP=4
setlocal EnableDelayedExpansion
<"!file!" >"!file!.~tmp" (
for /f %%i in ('type "!file!"^|find /c /v ""') do (
set "line1="& set /p "line1="
echo(!line1!
set "line2="& set /p "line2="
echo(!line2!
set "line3="& set /p "line3="
echo(!line3!
set "line4="& set /p "line4="
echo(!line4!
REM -------------------------------------------
echo SET K0="..\GAMEPATH.TXT"
echo FOR /F "Tokens=*" %%%%V IN ('TYPE %%K0%%'^) DO (SET K1=%%%%V^)
REM -------------------------------------------
for /l %%j in (1+SKIP 1 %%i) do (
set "line="& set /p "line="
echo(!line!
)
)
)
>nul move /y "!file!.~tmp" "!file!"
endlocal
i fed the file "zttag - skip insert rest 1.BAT" to the ztree version of batch file below, aGerman worked so well (including & and !), now i can skip where i want and insert how many lines i want. i will ask about operators like <"!file!" >"!file!.~tmp" some other time until i get to read some for it
Code: Select all
REM #ZTTag #ZTTemp\~ZTTag.bat -fCALL #ZTTemp\ZTW_MENU.BAT SUB %1
IF [%%1]==[SUB] GOTO SUB
CALL #ZTTemp\~ZTTag.bat
DEL #ZTTemp\~ZTTag.bat
GOTO :END
:SUB
"C:\ZTREE\BATCH2\zttag - skip insert rest 1.BAT" %%2
GOTO :END
:END
time to study aacini's batch