0

I wanted to create a file in my bash script using cat containing a TAB Char. However I couldn't manage to get it working. Here my tests:

Using plain tab:

cat >file.txt <<END
    Text after plain tab.
END

Result:

Text after plain tab.

Using ^I:

cat >file.txt <<END
^IText after escaped I.
END

Result:

^IText after escaped I.

Using \033I:

cat >file.txt <<END
\033IText after another escaped I.
END

Result:

\033IText after another escaped I.

Thanks in advance :-)

Leon Kasko
  • 117
  • 2
  • 7
  • The [topic](http://stackoverflow.com/help/on-topic) at Stack Overflow is programming and this question seems to have very little to do with that. I think you'd get better, and more, responses in a more suitable Stack Exchange site like [Unix & Linux](http://unix.stackexchange.com/). –  Jun 26 '15 at 08:35
  • Try without the `< – o11c Jun 26 '15 at 08:40
  • @SamiLaine I probably forgot to mention that I want to use this in my mailserver installer script. – Leon Kasko Jun 26 '15 at 09:22

2 Answers2

1

There are three examples shown. The first works (perhaps some detail was omitted). The other two (a literal "^I" and a literal "\033I") will not produce a tab because cat does not do that. It does provide an option (-v) for going the other way, making the nonprinting characters displayable.

As noted in another answer, the echo command can interpret some backslash sequences. For example

echo "\tExample with tab" >file.txt

There are some differences between the varieties of echo used on Linux as a standalone program (from coreutils) versus that which is part of the shell (perhaps bash or dash or zsh). The POSIX standard is a good place to start.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
0

You can easily use Echo and tab character \t as shown below:

[purnendu.maity@unix ~]$ echo  "Example with tab: \t text after tab" > file.txt
[purnendu.maity@unix ~]$ cat file.txt
Example with tab:        text after tab
pmr
  • 998
  • 2
  • 13
  • 27