2

How to force echo command to output a tab character in MS nmake makefile? Verbatim tabs inserted right into a string after echo command are removed by nmake and don't show up in the output file.

all :
    @echo I WANT TO OUTPUT THE <TAB> CHARACTER HERE! > output.txt
Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366

6 Answers6

4

You can use a variable with TAB char. Put this lines in your .bat file:

set tab=[stroke TAB char from your keyboard]
echo a%tab%b>yourfile.txt

Doing so, yourfile.txt will have text a[TAB]b

Eduardo Poço
  • 2,819
  • 1
  • 19
  • 27
0
output.txt:
    <<output.txt
I WANT TO OUTPUT THE <TAB> CHARACTER HERE!
<<KEEP

<TAB> represents a literal tab character here of course.

bobbogo
  • 14,989
  • 3
  • 48
  • 57
0

DOS and Windows have ugly text support in native batch files :).

Here is nice way to do your task:

  1. install Python interpretator
  2. write simple script which appends character with specified code to file
  3. call script wherever you want :)

Simple script:

'''
append_char.py - appends character with specified code to end of file

Usage:  append_char.py  filename charcode

'''
import os
import sys

filename = sys.argv[1]
assert os.path.exists(filename)

charcode = int(sys.argv[2])
assert 0 <= charcode <= 255

fh = open(filename, 'ab')
fh.seek(0, os.SEEK_END)
fh.write(chr(charcode))

fh.close()

using this script from batch file you can create any possible file in universe :)

Denis Barmenkov
  • 2,276
  • 1
  • 15
  • 20
0

I had the same need. I used the answer using the quotes around the character and just took it one step further.

{tab} means pressing the keyboard tab key in the text editor.

SET tab="{tab}"

SET tab=%tab:~1,1%

The second line extracts the middle character from the quoted string.

Now you can use the %tab% variable with ECHO and, I suspect, anywhere else it's needed.

ECHO %tab%This text is indented, preceded by a tab.

I suspect this technique could be used with other problem characters as well.

Richard Michael
  • 61
  • 1
  • 2
  • 3
0

As a workaround, you can create a file containing the tab character, named input.txt (not using nmake), and then say:

all :
    @copy /b input.txt output.txt
pts
  • 80,836
  • 20
  • 110
  • 183
0

I assume you already have tried to put the tab inside quotes?

all:
    @echo "<TAB>" > output.txt
hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • Yes, I've already tried this. The tab character is then present but quotes also which I don't want since using echo I'm creating another nmake makefile and when quotes are present it doesn't work. I need the tab character alone. Any idea how to avoid outputting quotes in this scenerio? – Piotr Dobrogost Apr 28 '09 at 19:10