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:
"Mark J. Reed" <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 18 May 2010 07:08:43 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (44 lines)
On Mon, May 17, 2010 at 10:02 PM, jeff donovan <[log in to unmask]> wrote:
> Greetings
>
> this is driving me nutz.
>
> using 10.6, from the terminal
>
> sed ' s/([\t]+)/[:]/g' tabfile > notabfile

(Note that your last attempt above, if it did work, would replace each
sequence of tabs with "[:]", including the literal brackets, which I
suspect is not what you want.  Regex on the left, literal on the
right.)

The Mac command-line tools are not, in general, the GNU versions you
might be familiar with from Linux.  Traditional sed does not expand C
escapes; if you want a tab or a newline, you have to put a literal tab
or newline (the latter backslash-escaped) inside the argument string.

Without the -E option (extended regular expressions), it also doesn't
understand the + (one or more) quantifier; instead of x+, you have to
use xx*.  But do you really want to collapse a sequence of multiple
tabs down to just one colon?  Your Perl example doesn't do that.

As Steven said, you can get a literal tab at the terminal by typing
control-V + tab.  Alternatively, you can use the escape-expanding
feature of bash's builtin echo:

sed -e "$(echo -e 's/\t/:/g')" tabfile >notabfile

which makes it a bit easier for humans to tell what's going on, and
for copy/paste purposes.

>  perl -pi -e 's/\t/:/g' filename

Note that if you drop the -i (inplace), the perl would behave the same
as the sed. So any reason not to just use perl?   Its regex syntax is
at least consistent across implementations, so anything that works on
the Mac will also work on Linux, etc.


-- 
Mark J. Reed <[log in to unmask]>

ATOM RSS1 RSS2