What is the easiest way to add a text to the beginning of another text file in Command Line (Windows)?
But, if you would like to add some text to the file, you can type in after this, like this: cat >> new. txt This is some text in the file from command line. To stop editing and saving in the file, simply type CTRL+C, it will create, save and exit the file.
To add the text at the beginning of the existing first line, use the -n argument of echo. Note that although Bash or many other shells do not have a limit on the size of a variable, however, the size may be limited based on the environment and system configuration.
You can move to another position in the file and use the put command to place the text in a new position. Although you can move any block of text, this command sequence is more useful with lines than with words. The put command, p , places saved or deleted text (in the buffer) after the cursor position.
Try using the conditional execution & or the && between each command either with a copy and paste into the cmd.exe window or in a batch file. Additionally, you can use the double pipe || symbols instead to only run the next command if the previous command failed.
echo "my line" > newFile.txt type myOriginalFile.txt >> newFile.txt type newFile.txt > myOriginalFile.txt
Untested. Double >> means 'append'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With