Re: Sed programming question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10Dec2008 18:39, Dan Thurman <dant@xxxxxxxxx> wrote:
> I think sed can handle relational operators, but I have not
> been able to figure it out. Am I correct in assuming that
> sed can use relational operators such as OR (|) or AND
> (&)?
>
> Here is an example, but does not work:
>
> echo "The" | sed -e '/(the)|(THE)|(The)/i\ GOOD!'
>
> I tried looking up examples on the Internet, but could
> not find it.  My brain is getting real mushy.

Sed doesn't directly do relational operators.
_If_ you are using GNU sed _and_ you use the -r option, then you have
"extended/full regular expressions", and they support "|" (alternation,
like OR).

"&" is not AND, it's a substitution syntax for "what was matched by the
left hand regexp", eg:

  s/bill/& and ted/

You can only do AND by nesting multiple pattern matches:

  /foo/{
    /bar/{
      ... do stuff for "foo" AND "bar"
    }
  }

although you can fake it at some performance expense thus:

  /(foo.*bah|bah.*foo)/{
    ... do stuff for "foo" AND "bar"
  }

This gets combinatorially worse for each additional AND you try to fake;
you are better off nesting matches as in the previous example.

Have you considered joining the sed-users list?

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

Frisbeetarianism: The belief that when you die, your soul goes up on the roof
and gets stuck. - Tony Molina <amolina@xxxxxxxxxxxxxx>

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux