views:

382

answers:

2

What is the easiest way to add a text to the beginning of another text file in Command Line (Windows)?

+1  A: 
type "my line" > newFile.txt
type myOriginalFile.txt >> newFile.txt
type newFile.txt > myOriginalFile.txt

Untested. Double >> means 'append'

DarkwingDuck
It'll be "echo" instead of "type" for the first line but thanks, It worked.
dr. evil
Er yeah, echo, sorry. :) I just spun that off the top of my head in case it helped you get along faster.
DarkwingDuck
+2  A: 

The following sequence will do what you want, adding the line "new first line" to the file.txt file.

ren file.txt temp.txt
echo.new first line>file.txt
type temp.txt >>file.txt
del temp.txt

Note the structure of the echo. "echo." allows you to put spaces at the beginning of the line if necessary and abutting the ">" redirection character ensures there's no trailing spaces (unless you want them, of course).

paxdiablo