On a windows batch file, what is the proper way to echo a TAB?

echo A<TAB>B<TAB>C

I know I can type the TAB char between entries, but most editors will display it as a sequence of spaces. Some will even automatically convert them to spaces, I'm looking for something more visual.

Clarification: <TAB> here means the real tab char. I'm looking for the the C \t in a batch script.

link|improve this question
You tried editors and found "most" display tab as a sequence of spaces? which are those? The first editor i'd have tried is notepad and that displays tabs as tabs. – barlop Nov 13 '11 at 19:12
feedback

3 Answers

up vote 2 down vote accepted

Just hit the TAB key in an editor that supports it, Notepad for example.

So, if I enter this:

@echo 1<TAB>b
@echo 2<TAB>c

It would result in this:

enter image description here

link|improve this answer
It works, and it's how I'm doing it. The problem is that anyone editing the file might replace an oddly positioned tab withouth noticing it's intentional. – Haas Feb 1 '11 at 19:53
@Haas: What about set TAB=<TAB> to clarify that it is the tab character and then using %TAB% afterwards? As far as I am aware, echo only parses %...%. There is no built-in tab character as far as I'm aware of... – Tom Wijsman Feb 1 '11 at 20:19
1  
That makes it clear and works. Thanks – Haas Feb 1 '11 at 20:33
copy con ........... – barlop Nov 13 '11 at 6:44
@barlop: What...............? xD – Tom Wijsman Nov 13 '11 at 12:57
feedback

As long as you are using an editor that keeps the tabs intect, you could download sed and put it on your path, and then you could do something like:

echo "A`B`C" | sed 's/\t/<TAB>/g'

where each ` is standing in for a real tab.

link|improve this answer
feedback

Limitations such as this are among the reasons to use Windows Script Host or Powershell.

Windows Script Host shipped (ships) with every Windows version from 98 on and can be installed on 95 and NT 4.

Create a file called demo.vbs and paste the following line in it and save it.

WScript.StdOut.WriteLine "a" + chr(9) + "b"

Now, from the directory where you saved it, enter:

demo.vbs

and you should see:

a       b

You can also do

cscript demo.vbs

which will allow you to use the command line switches that cscript provides.

(Tested on Vista.)

link|improve this answer
Powershell would be very nice, but it's not always availible... – Haas Feb 1 '11 at 19:54
@Haas: Please see my edited answer. – Dennis Williamson Feb 1 '11 at 20:51
Thanks Dennis. I'd love to use something newer and better, but it's the one option I have for this specific script. – Haas Feb 1 '11 at 21:06
@Haas: I just thought that "I'm looking for something more visual" was a requirement. – Dennis Williamson Feb 1 '11 at 21:12
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.