Re: Sed programming question

2008-12-12 Thread Kevin Martin


Dan Thurman wrote:
 Kevin Martin wrote:

 Gordon Messmer wrote:
  
 Dan Thurman wrote:

 I tested your suggestion above with and without -r option
 but could not make it work as an AND operator:

 # echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
 goo har
   
 $ rpm -q sed
 sed-4.1.5-11.fc10.x86_64

 $ echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
 foo har

 

 $ echo foo har  | sed -e s/foo/goo/g -e s/har/bar/g
 goo bar

 Is this what you're trying to do?

 Kevin
   
 No.  The result should be: (foo AND har) = (10)=0
 so the inside nested brackets should not be allowed to
 run and the original string (foo har) is returned.

 Dan

Ah, I missed the first part of the conversation where it was explained
what you were doing (ah, snipped mail).  Sorry for butting in.

Kevin

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


Re: Sed programming question

2008-12-11 Thread Dan Thurman

Cameron Simpson wrote:

On 10Dec2008 18:39, Dan Thurman [EMAIL PROTECTED] wrote:
  
[snip!]

You can only do AND by nesting multiple pattern matches:

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

I tested your suggestion above with and without -r option
but could not make it work as an AND operator:

# echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
goo har


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


Re: Sed programming question

2008-12-11 Thread Gordon Messmer

Dan Thurman wrote:

I tested your suggestion above with and without -r option
but could not make it work as an AND operator:

# echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
goo har


$ rpm -q sed
sed-4.1.5-11.fc10.x86_64

$ echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
foo har

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


Re: Sed programming question

2008-12-11 Thread Kevin Martin



Gordon Messmer wrote:
 Dan Thurman wrote:
 I tested your suggestion above with and without -r option
 but could not make it work as an AND operator:

 # echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
 goo har

 $ rpm -q sed
 sed-4.1.5-11.fc10.x86_64

 $ echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
 foo har


$ echo foo har  | sed -e s/foo/goo/g -e s/har/bar/g
goo bar

Is this what you're trying to do?

Kevin

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


Re: Sed programming question

2008-12-11 Thread Dan Thurman

Gordon Messmer wrote:

Dan Thurman wrote:

I tested your suggestion above with and without -r option
but could not make it work as an AND operator:

# echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
goo har


$ rpm -q sed
sed-4.1.5-11.fc10.x86_64

$ echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
foo har


$ rpm -q sed
sed-4.1.5-10.fc9.i386

Hmm...  I tried it again and it worked...
Must be a brain-f*rt on my part!

Thanks a lot for confirming!

Dan

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


Re: Sed programming question

2008-12-11 Thread Dan Thurman

Kevin Martin wrote:


Gordon Messmer wrote:
  

Dan Thurman wrote:


I tested your suggestion above with and without -r option
but could not make it work as an AND operator:

# echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
goo har
  

$ rpm -q sed
sed-4.1.5-11.fc10.x86_64

$ echo foo har | sed -re '/foo/{/bar/{s/foo/goo/}}'
foo har




$ echo foo har  | sed -e s/foo/goo/g -e s/har/bar/g
goo bar

Is this what you're trying to do?

Kevin
  

No.  The result should be: (foo AND har) = (10)=0
so the inside nested brackets should not be allowed to
run and the original string (foo har) is returned.

Dan

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


Sed programming question

2008-12-10 Thread Dan Thurman


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.

Kind regards,
Dan

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


Re: Sed programming question

2008-12-10 Thread Cameron Simpson
On 10Dec2008 18:39, Dan Thurman [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED]

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


Re: Sed programming question

2008-12-10 Thread Dan Thurman

Cameron Simpson wrote:

On 10Dec2008 18:39, Dan Thurman [EMAIL PROTECTED] 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,
  

Wow, thanks a lot!  I certainly realize now that relational operators
are quite limited with sed, which is why there weren't any examples
offered over the Internet!  Duh oh!

Thanks for the tip regarding joining the sed-users group!

Dan

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


Re: Sed programming question

2008-12-10 Thread Dave Feustel
On Wed, Dec 10, 2008 at 07:01:24PM -0800, Dan Thurman wrote:
 Cameron Simpson wrote:
 On 10Dec2008 18:39, Dan Thurman [EMAIL PROTECTED] 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,
   
 Wow, thanks a lot!  I certainly realize now that relational operators
 are quite limited with sed, which is why there weren't any examples
 offered over the Internet!  Duh oh!

 Thanks for the tip regarding joining the sed-users group!

 Dan

Depending upon what it is that you are trying to do, you might find
Phil Budne's CSnobol4 useful.

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