When adding to a file using Windows command commands, how to add immediately after the next word in the file?

When adding to a file using Windows command commands, how to add 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 03/29/2010

But I want the result to be like this:

here is the date 29-03-2010

How to avoid carriage returns when adding?

+3
source share
2 answers

The output echoalways includes the ending new line. To output text without a ending newline, you can use the trick set /pdescribed here and here :

< nul (set /p s=Today is ) > c:\arun.txt
date /t >> c:\arun.txt

%date% date /t, %date% :

echo Today is %date% > c:\arun.txt
+5

C:\test>set s=here is today 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 date    
+1

Source: https://habr.com/ru/post/1738996/


All Articles