Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

WwWXxX, udp high ports, d-link extract firmware dsl-2750u, wwwwxxxxx.2G, yxxxcom, WWWXXX, ftp://192.168.100.100, wwwxxx 100, www.xxxcon, wwwxxx

Links

XODOX
Impressum

#1: Can sed match a choice of two?

Posted on 2008-04-24 01:32:58 by simonp

I have a sed script that I need to add a pattern matching one of
two choices (.rar or .zip). I know this can be done in awk and
egrep with (rar|zip), but is there anyway to get this behaviour
in sed?

Do I have to rewrite my script in perl?

Cheers,
Simon

Report this message

#2: Re: Can sed match a choice of two?

Posted on 2008-04-24 01:51:26 by mop2

don't work /zip\|rar/ with sed?


sim...@nospam.com wrote:
> I have a sed script that I need to add a pattern matching one of
> two choices (.rar or .zip). I know this can be done in awk and
> egrep with (rar|zip), but is there anyway to get this behaviour
> in sed?
>
> Do I have to rewrite my script in perl?
>
> Cheers,
> Simon

Report this message

#3: Re: Can sed match a choice of two?

Posted on 2008-04-24 02:13:10 by Rajan

<simonp@nospam.com> wrote in message news:fuogva$ejs$1@reader2.panix.com...
> I have a sed script that I need to add a pattern matching one of
> two choices (.rar or .zip). I know this can be done in awk and
> egrep with (rar|zip), but is there anyway to get this behaviour
> in sed?
>
> Do I have to rewrite my script in perl?
>
> Cheers,
> Simon
>

I use gnu sed (if I have to) and I can say -r to make sed understand
extended regex. Alternatively, I can write it the script twice with -e with
different regexs (I won't do it). Calling sed experts....

Report this message

#4: Re: Can sed match a choice of two?

Posted on 2008-04-24 03:20:52 by Maxwell Lol

simonp@nospam.com writes:

> Do I have to rewrite my script in perl?

It's not too bad if you have to, using s2p (part of perl).

Report this message

#5: Re: Can sed match a choice of two?

Posted on 2008-04-24 04:05:28 by simonp

Rajan <rsharma@nodomain.no> wrote:
>
>
> <simonp@nospam.com> wrote in message news:fuogva$ejs$1@reader2.panix.com...
>> I have a sed script that I need to add a pattern matching one of
>> two choices (.rar or .zip). I know this can be done in awk and
>> egrep with (rar|zip), but is there anyway to get this behaviour
>> in sed?
>>
>> Do I have to rewrite my script in perl?
>>
>> Cheers,
>> Simon
>>
>
> I use gnu sed (if I have to) and I can say -r to make sed understand
> extended regex. Alternatively, I can write it the script twice with -e with
> different regexs (I won't do it). Calling sed experts....
>

This is the solution. The -r option (-E in my FreeBsd shell
account) enables extended pattern regex.

I actually looked this up in Linux in a Nutshell from O'Reilly.
They have a grid with all the utilities like ed, awk, grep, sed
and what they can do. Extended regex was *not* tagged for sed,
though it was for grep. (Though it is there in the dedciated
chapter on sed). Must be an error.

Thanks again,
Simon

Report this message

#6: Re: Can sed match a choice of two?

Posted on 2008-04-24 04:30:02 by simonp

mop2 <mop2bky4mz5tyjwa8ersp7hrg5u9qn@gmail.com> wrote:
> don't work /zip\|rar/ with sed?
>
>
> sim...@nospam.com wrote:
>> I have a sed script that I need to add a pattern matching one of
>> two choices (.rar or .zip). I know this can be done in awk and
>> egrep with (rar|zip), but is there anyway to get this behaviour
>> in sed?
>>
>> Do I have to rewrite my script in perl?
>>
>> Cheers,
>> Simon

This is what I go to work:

s/(rar|zip|txt|jpg) +- +/\1 ::INFO:: /g

The match in the group of file extensions is stored, then kept,
with extra text appended.

Is there any consistently in what has go be escaped in extended
regexp? The () did not need to be escaped here, but to use what
was stored you still need the escape \1.

-Simon

Report this message

#7: Re: Can sed match a choice of two?

Posted on 2008-04-24 05:29:58 by Ed Morton

On 4/23/2008 6:32 PM, simonp@nospam.com wrote:
> I have a sed script that I need to add a pattern matching one of
> two choices (.rar or .zip). I know this can be done in awk and
> egrep with (rar|zip), but is there anyway to get this behaviour
> in sed?
>
> Do I have to rewrite my script in perl?

Apparently not because, as you said:

> I know this can be done in awk and
>> egrep with (rar|zip)

Ed.

Report this message

#8: Re: Can sed match a choice of two?

Posted on 2008-04-24 05:34:57 by Ed Morton

On 4/23/2008 9:30 PM, simonp@nospam.com wrote:
> mop2 <mop2bky4mz5tyjwa8ersp7hrg5u9qn@gmail.com> wrote:
>
>>don't work /zip\|rar/ with sed?
>>
>>
>>sim...@nospam.com wrote:
>>
>>>I have a sed script that I need to add a pattern matching one of
>>>two choices (.rar or .zip). I know this can be done in awk and
>>>egrep with (rar|zip), but is there anyway to get this behaviour
>>>in sed?
>>>
>>>Do I have to rewrite my script in perl?
>>>
>>>Cheers,
>>>Simon
>>
>
> This is what I go to work:
>
> s/(rar|zip|txt|jpg) +- +/\1 ::INFO:: /g
>
> The match in the group of file extensions is stored, then kept,
> with extra text appended.
>
> Is there any consistently in what has go be escaped in extended
> regexp?

Yes.

> The () did not need to be escaped here, but to use what
> was stored you still need the escape \1.
>
> -Simon

The \1 isn't part of an extended regexp, it's the sed operator to backreference
part of a matched regexp. In GNU awk the equivalent is \\1.

Ed.

Report this message

#9: Re: Can sed match a choice of two?

Posted on 2008-04-24 19:29:17 by Dave B

On Thursday 24 April 2008 01:32, simonp@nospam.com wrote:

> I have a sed script that I need to add a pattern matching one of
> two choices (.rar or .zip). I know this can be done in awk and
> egrep with (rar|zip), but is there anyway to get this behaviour
> in sed?

If you /absolutely/ need to do that with standard sed, then you can do
something like (depending upon what you want to do after the match,
anyway):

/\.rar/b found
/\.zip/b found

....

:found
....


However, I think you better do that with GNU sed, if you can, or use another
tool. You've already got good answers.

--
D.

Report this message