views:

132

answers:

2

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-2010

But I want the output to be like this:

here is the date of 29-03-2010

How to avoid carrage return while appending?

+1  A: 

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    
ghostdog74
i want to append in already present text file
Arunachalam
is there any other way ?
Arunachalam
+3  A: 

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
Helen
`%date%` is no environment variable. It's merely a pseudo-variable expanded to the current date by the shell.
Joey
thank u .do u know how to append a empty line in the text file ?
Arunachalam
@Arunachalam: Try `echo.>>file.txt`
Helen