Re: Sed programming question

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

 



On Wed, Dec 10, 2008 at 07:01:24PM -0800, Dan Thurman wrote:
> Cameron Simpson wrote:
>> 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,
>>   
> 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@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux