0
set NUMBER=0

echo 3.3.3.%NUMBER% > "file.txt"

after running this command the content of file.txt is 3.3.3.0 with extra space after the 0

I would like to remove the extra space, how this can be done?

EDIT

I following the answer of bgoldst the extra space is gone, however now I have extra line break. I want to remove it

I found some answers for solving the extra line, however I don't want space not new line in the file

user829174
  • 6,132
  • 24
  • 75
  • 125
  • possible duplicate of [Using echo without trailing space in DOS](http://stackoverflow.com/questions/12505552/using-echo-without-trailing-space-in-dos) – Raymond Chen Jun 09 '15 at 09:23

2 Answers2

1

The space is introduced by the echo command because there is a space between the %NUMBER% variable and the > redirection operator. The echo command respects trailing whitespace in its command-line.

Thus, you can solve this by removing that space (and you can also remove the quotes, as well as the space between the > and the file.txt, since they are not necessary):

echo 3.3.3.%NUMBER%>file.txt
bgoldst
  • 34,190
  • 6
  • 38
  • 64
1

Building on the answer by bgoldst

To remove the space and the line feed:

<nul set /p=3.3.3.%NUMBER%>file.txt

See Windows batch: echo without new line for more information.

Community
  • 1
  • 1
DavidPostill
  • 7,734
  • 9
  • 41
  • 60