computing
  • 0

Solved Batch Script To Copy Lines From One Text File To Another

  • 0

Hi,

Below script is used to copy lines from a text file to other

May i know how can I use the below script to copy the text at the beginning of the output file. Currently it is appending at the end of the file

@ECHO OFF
setlocal enabledelayedexpansion

SET /P maxlines=Enter number of lines to be moved to new txt document:
SET /A linecount=0

FOR /F “delims=” %%A IN (textfile1.txt) DO (
IF !linecount! GEQ %maxlines% GOTO ExitLoop
ECHO %%A >> C:\users\username\desktop\textfile2.txt
SET /A linecount+=1
)

:ExitLoop
ECHO All Done.
ECHO.
ECHO Press any key to close this window.
PAUSE>NUL
EXIT

Share

1 Answer

  1. echo final result IN TMP. copy to dest or add the final move to batch-script…
    type tmp
    echo done.

    this line:
    rem move tmp %dest%
    should, or is supposed to, do the trick, by removing the ‘rem’ so it looks like:

    move /y tmp %dest%

    this will overwrite your destination file, so I left it de-activated pending feedback of fail or success. Be sure, until you are sure, to back up your destination files just in case something does go wrong.
    ps: the “/y” was added to keep the system from asking “are you sure?” every time.

    message edited by nbrane

    • 0