On May 18, 2010, at 7:08 AM, Mark J. Reed wrote:
> 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.)
so the right side {replace} is literal ?
so should be able to sed 's/{myregex}/literal/g'
no regex commands in the replace?
>
> 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.
for some reason I thought that's what \t represented, I have also seen the use of an ascii representation
>
> 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
okay so ,.. like my next endeavor
i want to change this;
/usr/bin/perl -pi -e 's/\r\n?/\n/g' dosfile
which removes dos line feeds and replaces with newlines
to
sed -e"$(echo -e 's/\r\n?/\n/g')" dosfile > mytext
## that didn't work.
nc1-100:HERE drfoo$ sed -e "$(echo -e 's/\r\n?/\n/g')" dosfile > mytext
sed: 1: "s/\r\n?/\n/g\n": unterminated substitute pattern
nc1-100:HERE drfoo$ sed -e "$(echo -e 's/\r\n?/^M/g')" dosfile
sed: 1: "s/\r\n?/\r/g\n": unterminated substitute pattern
here i go again
>
> 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?
Im trying to consolidate a script, this perl has been fine. I still may go back to it. But i would like to try other ways. some may be quicker. some take less resources. Some are just easier for me to keep straight :) i may re-write this script and not touch it for a year or two, and then have to come back and say " why was I using this ? ". even my notes sometimes don't tell me what the heck.
> Its regex syntax is
> at least consistent across implementations, so anything that works on
> the Mac will also work on Linux, etc.
Thanks Mark,
|