0

I want to insert the following command to the 1st line & a self destruct command to the last line of another batch

if not "%1" == "max" start /MAX cmd /c %0 max & exit/b

my batch:

@echo off
if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
CD %~dp0mkvtoolnix
pause. >nul | echo. Press Enter To Analyze MKV Files
echo.  Analyzing MKV Files
@echo on
%~dp0ChapterUnorderer.exe %~dp0 [-o] [-f]

<New command that  I require>

@echo off
pause. >nul | echo.  Press Enter To Remux
START %~dp0ChapterUnorderer.bat

pause
del "%~dp0ChapterUnorderer.bat"

EDIT this batch cant have absolute paths & my batch has spaces in the name if that helps

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Mav
  • 47
  • 1
  • 5

1 Answers1

0

For your prepend:

Echo New first line>Newfile
more oldfile>>newfile
ren oldfile oldfile.bak
ren newfile oldfile

If you want to replace the first line in oldfile insert +1 following more.

For the self destruct see this answer from @dbenham

Community
  • 1
  • 1
  • more like insert a command by creating and shifting the rest of the commands one line below in the batch – Mav Mar 02 '17 at 22:02
  • This is the simplest approach for the first line, there is no sed delivered with windows. But to give you [a more versatile answer](http://stackoverflow.com/questions/42006613/insert-specific-text-after-line-2-with-batch-programming) –  Mar 02 '17 at 22:15
  • wow thats exactly what I need but it inserts to the first line, I need the top most line to be inserted – Mav Mar 02 '17 at 22:25
  • You choose the line number by editing `If %%A Neq 2` –  Mar 02 '17 at 22:30
  • already tried it inserted the line below first when I wrote Neq 1 – Mav Mar 02 '17 at 22:38
  • Well the batch is written to insert below the numbered line, if you want to change to insert before reverse the following two echo lines. –  Mar 02 '17 at 22:40
  • @Mav Changed the referenced batch to be more descriptive, would be nice to get a vote up on either or an accepted answer here. –  Mar 02 '17 at 23:45