Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using echo without trailing space in DOS

Tags:

echo

dos

space

I noticed that when I use echo to print something to a file in DOS, a space is appended to the string. I need to print the string without the trailing space. Is there a way to do that, or as a workaround, remove trailing spaces from the file?

like image 788
Rayne Avatar asked Sep 20 '12 03:09

Rayne


2 Answers

If I understood the problem correctly, you wrote the trailing space.

Instead of

echo string > file

use

echo string>file
like image 79
Dennis Avatar answered Dec 04 '22 22:12

Dennis


Assuming you're talking about cmd.exe rather than the actual (rather outdated) MSDOS, there are a number of ways to do this, the first being:

echo Here is some text>output.txt

but I find that somewhat less than readable since I'm used to being able to clearly delineate 'arguments' on the command line.

Alternatively, there's nothing stopping you from swapping around the order of your command line:

>output.txt echo Here is some text

which will allow you to still separate the arguments whilst not having extraneous spaces put in your output file.

In fact, I've often used this method for blocks of code as well:

>output.txt (
    echo hello
    echo goodbye
)

which will write both lines to the file. I find it preferable in that case since you know right at the start where the output is going, rather than having to go and look at the end of the code block.

like image 27
paxdiablo Avatar answered Dec 04 '22 21:12

paxdiablo