2

Is there any way to have this:

echo test line > t.txt

run in a windows batch file or makefile use a unix line ending (\n) instead of a windows one (\r\n)?

Baruch
  • 17,941
  • 22
  • 109
  • 186
  • Are you restricting yourself to tools that are available on a vanilla install? If not then you could use a better scripting language that .bat files. – David Heffernan Mar 26 '12 at 17:00
  • @DavidHeffernan I would really rather use only default tools. If it is totally impossible, I can accept something else, but preferably a tool to do this and not another scripting language, as I want to use this from a makefile – Baruch Mar 26 '12 at 17:04
  • Which tool does not accept Windows line ends? Isn't that the tool that you should be fixing? – David Heffernan Mar 26 '12 at 17:46
  • @DavidHeffernan The "tool" is VS, and it accepts all line ends. I am just creating some source files by writing some lines into a file as it's header and then copying a whole file into it. The files I am copying are UNIX line-endings, so I end up with a file with mixed line-endings. Every time I open a file like this in VS I get prompted to convert line endings. It is annoying. – Baruch Mar 26 '12 at 21:04
  • Can't you just run unix2dos on it? – David Heffernan Mar 26 '12 at 21:07
  • @DavidHeffernan I am not familiar with it. What is it? – Baruch Mar 27 '12 at 08:40
  • Type that name into websearch. – David Heffernan Mar 27 '12 at 08:58

2 Answers2

1

Combining answers from here Windows batch: echo without new line and here Is it possible to put a new line character in an echo line in a batch file?

SET LF=^


REM important to have two blank lines after the SET command
<NUL set /p=test line^%LF%%LF%> t.txt
Community
  • 1
  • 1
lessthanideal
  • 995
  • 12
  • 13
1

No, you can't do it using echo. Echo works by simply writing a line of text followed by a CR/LF pair (the Windows line ending characters). Redirecting to a file just sends that line of text to a file handle instead of stdout. There's no way to modify the line ending characters used.

Ken White
  • 117,855
  • 13
  • 197
  • 405