Solved Batch. Copy and replace multiple files at once.

September 24, 2015 at 14:56:26
Specs: Windows 7
Hello. I would like to copy and replace the first x lines of a text file to another text file. Is there a way to do this with a batch script? Is it possible to put multiple text files as a source and multiple files as a target?

See More: Batch. Copy and replace multiple files at once.

Report •

September 25, 2015 at 18:16:16
hello there. assuming the former text file to be old.txt and the text file where to be copied is new.txt, this is a batch file code. copy this code to a text file and save it as anything.bat
setlocal enabledelayedexpansion

echo Created by jaysarma987
echo .
SET /P maxlines=Enter number of lines to be moved to new txt document:
SET /A linecount=0

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

ECHO All Done.
ECHO Press any key to close this window.
msg * This Utility was created bY jaysarma987

i hope this works out for u.

Report •

September 26, 2015 at 22:31:10
✔ Best Answer
Two subroutines: The first gets the "top" 'n' lines of file #1, the second gets the last 'm' lines of file #2
echo USAGE %0 file1 stopline# file2 startline# [destination] -- FILE 'TEMP' WILL BE DESTROYED
:: remove the pause as needed in foll. line
@echo off & setlocal
set dest=%5
call toplines %1 %2 > temp
set /a x=%4-1
more +%x% "%~3" >>temp
if defined dest move temp %dest%
goto :eof

::--------- toplines
@echo off & setlocal
set e=%2
set /a e+=1
if %e% leq 0 goto :eof

for /f "tokens=1* delims=[]" %%a in ('find /v /n ""^<"%~1"') do (
if %%a equ %e% goto :eof
echo %%b
::----------- end scripts
note that any combination of [] brackets at beg. of a line in file #1 might screw this.

message edited by nbrane

Report •

September 27, 2015 at 03:28:35
try mine first :)

Report •

Related Solutions

September 27, 2015 at 06:31:50
"copy and replace the first x lines of a text file"

I'll stay tuned to find out what that means.


M2 Get custom script or take private lessons

Report •

Ask Question