Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|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
up vote 9 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

share|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
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

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:


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.)

share|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

One solution is that you can set an environment variable called TAB and set the value to the actual tab character. You may need to copy and paste the tab character from a text editor to get it to be entered correctly. I have tried this in Windows 7 and it works.

In your batch file, just use %TAB% and it will insert a tab character.

share|improve this answer
+1 sombody voted you down maybe if this answer can be found somewhere in the comments. But answers should be found in the answers and not in the comments therefore an upvote from me – miracle173 Aug 21 '13 at 16:04

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.

share|improve this answer

Here is a one line solution using powershell in a batch file:

Powershell -noprofile -nologo -command Write-Output "a`tb`tc"

the `t is the tab character

share|improve this answer
Ah, powershell is taboo unless someone has already said it. – Pacerier Jul 29 '15 at 4:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .