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

Re: Sed programming question

On 10Dec2008 18:39, Dan Thurman <dant cdkkt com> 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:

      ... do stuff for "foo" AND "bar"

although you can fake it at some performance expense thus:

    ... 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?

Cameron Simpson <cs zip com au> DoD#743

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

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