On May 18, 2010, at 12:24 AM, Steven D. Majewski wrote:
> 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
Thanks for the feedback. yes this did work in the terminal. then i added the same line to Applescript with a do shell script. and in that case i did have to enter a regular tab.
do shell script "cat tab1 | sed -E 's/ /:/g' > tab2 "
from shell I used Command V, in applescript i used a keyboard Tab entry.
>
> 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:
thanks,.. i also used"tr" & "perl" it was sed that was driving me crazy. Thanks for the clarification.
>
> $ tr -s '\t' ':'
> 1 2 3
> 1:2:3
>
> will do the same thing with less fuss.
>
|