|
From: simonp on 23 Apr 2008 22:30 mop2 <mop2bky4mz5tyjwa8ersp7hrg5u9qn(a)gmail.com> wrote: > don't work /zip\|rar/ with sed? > > > sim...(a)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
From: Ed Morton on 23 Apr 2008 23:29 On 4/23/2008 6:32 PM, simonp(a)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.
From: Ed Morton on 23 Apr 2008 23:34 On 4/23/2008 9:30 PM, simonp(a)nospam.com wrote: > mop2 <mop2bky4mz5tyjwa8ersp7hrg5u9qn(a)gmail.com> wrote: > >>don't work /zip\|rar/ with sed? >> >> >>sim...(a)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.
From: Dave B on 24 Apr 2008 13:29 On Thursday 24 April 2008 01:32, simonp(a)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.
First
|
Prev
|
Pages: 1 2 Prev: China OEM Microphone - OEM OEM Microphone Manufacturer Next: grep doubt |