Page 1 of 1

how to copy and paste data at the beginning of a file?

Posted: 12 Feb 2011 13:10
by dominion
Hi i'm trying to extract 10first lines of from a text file and paste it at the beginning of an existing file.
i try this code but when it pastes data it just deletes the existing data .
how could i modify this code?


Code: Select all

@echo off & setLocal enableDELAYedeXpansion

set N=
(for /f "tokens=* delims= " %%a in (myfile) do (
  set /a N+=1
  if !N! gtr 10 goto :done
  echo.%%a
)) > some.txt
:done


Thank you

Re: how to copy and paste data at the beginning of a file?

Posted: 12 Feb 2011 13:43
by aGerman
Try that

Code: Select all

@echo off & setLocal enableDELAYedeXpansion

set N=
(for /f "tokens=* delims= " %%a in (myfile) do (
  set /a N+=1
  if !N! gtr 10 goto :done
  echo.%%a
))>tmp.txt
:done
copy /b tmp.txt + some.txt tmp2.txt
move tmp2.txt some.txt
del tmp.txt

Regards
aGerman

Re: how to copy and paste data at the beginning of a file?

Posted: 12 Feb 2011 15:54
by dominion
Hello,

thanks a lot
it's working fine.

Dominion :D