Reputation: 43558
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
Reputation: 59526
To stay in your context of using shell internal replacement while expanding variables:
str=$'foo\tbar'
echo "${str//$'\t'/,}"
Upvotes: 3
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