MACSCRPT Archives

May 2010

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Steven D. Majewski" <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 18 May 2010 00:24:14 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (49 lines)
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.

ATOM RSS1 RSS2