How to copy only 10 first lines from a text

February 11, 2011 at 11:27:07
Specs: Windows 7
Hi to all,

i would like to copy only 10 first lines from a text and copy into another existing file.

my project is:

1-get last update files from a directory => done in java
2-concatenate files from this directory into on file =>done in java
3-delete some specific lines from the concatenated file=>done in batch file
4-i want to copy the 10 first line from a file in batch file

could any one help me please.
i was using dos command in 1988 with an old pc but i don't remenber today.
thank you


See More: How to copy only 10 first lines from a text

Report •


#1
February 11, 2011 at 11:46:40
:: ==========================================
::
:: firstten.bat Sat 12-02-2011 2:43:03.56
@echo off & setLocal enableDELAYedeXpansion

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


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
February 11, 2011 at 12:26:58
Thank you for your quick reply but your batch file copy and paste the entire myfile to the existing file after 10 lines.


i want to copy 10 first line from myfile and paste it to the existing file
maybe i wasn't clear
thanks


Report •

#3
February 11, 2011 at 13:51:22
"Thank you for your quick reply but your batch file copy and paste the entire myfile to the existing file after 10 lines."

It didn't for me.


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
February 11, 2011 at 17:10:36
Hey M2,

I also tested it, and as I expected, it worked perfectly. Maybe the OP is leaving out some information?

Can I put a question here?


Report •

#5
February 11, 2011 at 17:26:40
I suspect the problem is where he wants it pasted in the resulting file. Maybe something like this?
@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
copy /a some.txt+existing.txt someother.txt
move someother.txt existing.txt & del some.txt

How To Ask Questions The Smart Way


Report •

#6
February 12, 2011 at 01:17:24
I tried for a second time, it extracts 10 lines from myfile and paste it at the end of the existing file.

i'm trying
thank you


Report •

#7
February 12, 2011 at 03:19:23
I tried your batch file but this time, it copies the 10 first lines from myfile and paste it on existing file and it deletes all the others existing datas.

i have to find the good combination

thank you


Report •

#8
February 12, 2011 at 13:53:53
thank you guys now it's working
i made a mistake
sorry
bye

Report •

Ask Question