Take the 2-minute tour ×

The closest I can come up with is:

echo 123 > out.txt

However this gives a trailing space and also a trailing newline.

share|improve this question

migrated from serverfault.com Oct 13 '12 at 21:24

This question came from our site for system and network administrators.

Echo and cat are different beasts - cat reads a file, echo prints what you give it on the commandline. What are you trying to do? –  Tom Newton Oct 11 '12 at 20:14
@TomNewton Basically, I am creating some scripts in TeamCity to be run during a deployment process. I need to basically create a text-file from a script that is then later read in by another script during another process –  CoolUserName Oct 11 '12 at 20:19
Then leave out the space before after the ">", and strip the trailing newline when you read the file. –  John Gardeniers Oct 11 '12 at 20:38
The original title referred to cat 123 > out.txt; I've just edited it to refer to echo. –  Keith Thompson Oct 13 '12 at 21:28

5 Answers 5

up vote 3 down vote accepted


coreutils contains "echo". You can use the "-n" flag to supress the trailing newline

share|improve this answer

In PowerShell:

write-output 123 | out-file test.txt

There is no trailing space, but there is a newline.

If you want to do this in cmd, the answer you provided in your question is the "correct" way, but there are obvious formatting issues

share|improve this answer

I've used this with success:

echo|set /p="123" > test.txt
share|improve this answer
+1 Neat, although the result still has the trailing space. Tweaked: >text.txt (echo|set /p="123") –  Ansgar Wiechers Oct 11 '12 at 21:04
Ah, my mistake. The output has a trailing space when the double quotes are omitted (set /p=123). It's fine with the double quotes in place (set /p="123"). –  Ansgar Wiechers Oct 11 '12 at 21:25
It's because you type a space in front of the >. –  Tom Wijsman Oct 13 '12 at 21:34
It worked for me as-is. –  Brian Oct 15 '12 at 13:07

I think you want this for text-based output:

type filename > output.txt
share|improve this answer
type only works with existing files it seems. In my case, I want to be able to specify the text inline. –  CoolUserName Oct 11 '12 at 20:17
@CoolUserName: Then your use of "cat" in your question is misleading. –  Brian Oct 11 '12 at 20:56

Use copy con

C:\tmp>copy con mynewfile
This is my new file
I am typing stuff
        1 file(s) copied.

C:\tmp>type mynewfile
This is my new file
I am typing stuff

Press Control-Z to end input

'con' is a keyword signifying console.

copy src dest

copy con mynewfile

src - con - console

dest - mynewfile - destination

share|improve this answer

Your Answer


