When appending to a file using Windows batch commands, how to append immediately after the next word in the file?
29,664
Solution 1
The echo
output always includes a trailing new line. To output text without a trailing new line, you can use the set /p
trick described here and here:
< nul (set /p s=Today is ) > c:\arun.txt
date /t >> c:\arun.txt
But in this specific case, you can simply use the %date%
variable instead of date /t
, as %date%
uses the same format:
echo Today is %date% > c:\arun.txt
Solution 2
you can store to a variable and append
C:\test>set s=here is today's date
C:\test>for /F "tokens=*" %i in ('date /t') do set d=%i
C:\test>set d=Tue 03/30/2010
C:\test>echo %d%%s%
Tue 03/30/2010 here is today's date
Comments
-
Arunachalam about 4 years
When appending to a file using Windows batch commands, how to append immediately after the next word in the file?
For example, these commands
echo here is the date of > c:\arun.txt date /t >> c:\arun.txt
write the following text to the arun.txt file:
here is the date of
29-03-2010But I want the output to be like this:
here is the date of 29-03-2010
How to avoid carrage return while appending?
-
Rich about 14 years
%date%
is no environment variable. It's merely a pseudo-variable expanded to the current date by the shell. -
Arunachalam about 14 yearsthank u .do u know how to append a empty line in the text file ?
-
Helen about 14 years@Arunachalam: Try
echo.>>file.txt