What is the easiest way to add a text to the beginning of another text file in Command Line (Windows)?
相关问题
- Inheritance impossible in Windows Runtime Componen
- how to get running process information in java?
- Is TWebBrowser dependant on IE version?
- How can I have a python script safely exit itself?
- I want to trace logs using a Macro multi parameter
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Bundling the Windows Mono runtime with an applicat
- Windows 8.1 How to fix this obsolete code?
- Compile and build with single command line Java (L
- CosmosDB emulator can't start since port is al
- How to print to stdout from Python script with .py
The following will also work:
In the first line you are writing my line into newfile.txt. In the second line you are replacing the text from myOriginalFile.txt by overwriting it with the text from newfile.txt and myOriginalFile.txt, creating a new myOriginalFile.txt that contains both.
Untested. Double >> means 'append'
Another variation on the theme.
Advantages over other posted answers:
The following sequence will do what you want, adding the line "
new first line
" to thefile.txt
file.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).If the first part of the line can be sorted, such as date/time then use the SORT /R command to put the most recent entries at the top of the file. The following will place a date/time stamp in the form of "YYYY-MM-DD HH:DD:SS AM/PM" to the start of each line:
However, as files grow very large this method (as well as the ones above) become slow. Consider sorting only when required instead of with each entry - or use another scripting/programming language