Re: generous sed?

From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 07/13/04


Date: Tue, 13 Jul 2004 17:24:37 GMT

On Tue, 13 Jul 2004 11:25:33 -0500, Ed Morton <morton@lsupcaemnt.com> wrote:
>
>
> How can I get sed to be less greedy when matching REs. I have an input
> file like:
>
> abc [ def ] ghi [ klm ] nop
>
> and I'd like to output:
>
> abc ghi nop
>
> There isn't always white space before or after the "[" or "]" - I just
> want to get rid of whatever is withing the square brackets.
>
> Initially, I didn't expect to ever see 2 sets of square brackets on one
> line so I had:
>
> sed 's/\[.*\]/'
>
> but of course that outputs this for the above input:
>
> abc nop
>
> I know how to do this in awk, but I have a few other things I'm doing
> with that sed command and I'd rather not convert it all to awk at this
> time or introduce a pipe between sed/awk.
>
> Regards,
>
> Ed.
>

s/\[[a-zA-Z0-1]\]//g

?

AC



Relevant Pages

  • generous sed?
    ... How can I get sed to be less greedy when matching REs. ... want to get rid of whatever is withing the square brackets. ... I didn't expect to ever see 2 sets of square brackets on one ... I know how to do this in awk, but I have a few other things I'm doing ...
    (comp.unix.shell)
  • Re: generous sed?
    ... Ed Morton wrote in message news: ... > How can I get sed to be less greedy when matching REs. ... > want to get rid of whatever is withing the square brackets. ...
    (comp.unix.shell)
  • Re: [9fans] Plan9 awk vs. GNU awk
    ... didn't track it down to be sure, but plan 9 awk seem to have a limit ... 34 characters inside square brackets. ... a rather odd number ...
    (comp.os.plan9)