What is the easiest way to add a text to the beginning of another text file in Command Line (Windows)?
views:
382answers:
2
+1
A:
type "my line" > newFile.txt
type myOriginalFile.txt >> newFile.txt
type newFile.txt > myOriginalFile.txt
Untested. Double >> means 'append'
DarkwingDuck
2009-02-15 11:23:06
It'll be "echo" instead of "type" for the first line but thanks, It worked.
dr. evil
2009-02-15 11:34:31
Er yeah, echo, sorry. :) I just spun that off the top of my head in case it helped you get along faster.
DarkwingDuck
2009-02-16 10:52:12
+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
2009-02-15 12:18:21