MOHAMED
MOHAMED

Reputation: 43558

How to replace a tabulation in shell bash linux

to replace a spaces by , (as example) in a giving string in shell I use the following command

str=${str// /,}

How to replace a tabulation by , in a string?

I tried

str=${str//\t/,}

But it does not work

Upvotes: 1

Views: 422

Answers (2)

Alfe
Alfe

Reputation: 59526

To stay in your context of using shell internal replacement while expanding variables:

str=$'foo\tbar'
echo "${str//$'\t'/,}"

Upvotes: 3

fedorqui
fedorqui

Reputation: 290115

You can use tr for this:

$ cat a
hello   how are you?    blabla

$ tr '\t' ',' <a
hello,how are you?,blabla

Upvotes: 3

Related Questions