How do I echo a TAB char on a command prompt
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.
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:
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.
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.)
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