On May 17, 2010, at 10:02 PM, jeff donovan wrote:

> Greetings
>
> this is driving me nutz.
>
> using 10.6, from the terminal
>
> sed ' s/([\t]+)/[:]/g' tabfile > notabfile
>
> trying to search and replace tabs from a file in bash. I can do it  
> in perl, perl -pi -e 's/\t/:/g' filename but not with sed. Ive tried  
> it from a simple cat tabfile | sed 's/\t/,/g'
>
> any assistance would be helpful.
> -j

I think for sed, it has to be an actual tab character and not the  
escape "\t" .
Unfortunately, with tab completions in bash turned on, you have to  
either
type: Control-V tab  to insert a literal tab, or use some other trick.


This works ( using control-V tab ):

$ sed -E "s/   +/:/g"
1	2		3
1:2:3

Another way to get the tab character:

$ T=$(echo "." | tr '.' '\t' )

$ sed -E "s/${T}+/:/g"
1	2		3
1:2:3

But, as long as we're bringing up 'tr' : 'tr' has a '-s' option to  
reduce multiple chars
to a single one, so:


$ tr -s '\t' ':'
1	2		3
1:2:3

will do the same thing with less fuss.