I need to add a single spacebar to a textfile ussing batch
however the following dosnt work
ECHO >C:\txt.txt
this produces the text Echo is (off) instead???
Im ussing windows batch
echo
is printing the text "ECHO if off" because you haven't provided any parameters to it. If you type echo /?
for usage instructions you will see this behavior defined: "Type ECHO without parameters to display the current echo setting". So, in your case, echo is set to off.
If you want to have on the space character without a newline and carriage return you will most likely need to use set
. If you are using Windows XP, this should be easy.
>txt.txt ( <nul set /p "= " )
If you are running Vista or Higher it keeps a little tricky because windows strips leading spaces on the set command.
You will need to create a backspace character and then print that:
:: Create a backspace character
for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set BS=%%A
<nul set /p=%BS% > txt.txt
Note that this doesn't actually print a space, but a backspace character instead. I'm not quite sure if this will work for you, but I couldn't think of any easier way. Otherwise you are probably better off using some other scripting language, like python or powershell.
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