Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
dominion
- Posts: 6
- Joined: 12 Feb 2011 12:35
#1
Post
by dominion » 12 Feb 2011 13:10
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
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 12 Feb 2011 13:43
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
-
dominion
- Posts: 6
- Joined: 12 Feb 2011 12:35
#3
Post
by dominion » 12 Feb 2011 15:54
Hello,
thanks a lot
it's working fine.
Dominion