Operating System - Linux
1828457 Members
3680 Online
109978 Solutions
New Discussion

Insert special character in text file

 
SOLVED
Go to solution
Leo The Cat
Regular Advisor

Insert special character in text file

Hi

I'd like to do something like that:

echo $1$2

But between $1 and $2 I'd like to insert a TAB character (ascii 9).

How to do this small trick ?

Bests Regards
Den
5 REPLIES 5
Shoghi Martinez G.
Honored Contributor
Solution

Re: Insert special character in text file

Hi leo \t will do the tab output.

echo "$1\t$2"
Shoghi Martinez G.
Honored Contributor

Re: Insert special character in text file

note the "quotes"
Leo The Cat
Regular Advisor

Re: Insert special character in text file

Shogi answer is perfect.
Steven Schweda
Honored Contributor

Re: Insert special character in text file

You could just use a Tab character, too. The
quotation marks are the critical things.

Among uncounted other possibilities:

bash$ a=A
bash$ b=B
bash$ echo "$a $b"
A B
bash$ echo $a' '$b
A B

(Due to Forum limitations, you'll need to
imagine that there are actual Tab characters
in there.)

Using a Tab character may be unwise, however,
if you're actually sending it to a terminal
(or emulator). What you see on a terminal
depends on the terminal's tab settings, over
which you may have little or no control. The
result can be very ugly output.
Maaz
Valued Contributor

Re: Insert special character in text file

I think Shoghi Martinez G. solution works 100% if "-e" will be used

echo -e "$1\t$2"

Regards