OT: simple regex question
Jacques B.
jjrboucher at gmail.com
Mon Apr 23 10:39:19 UTC 2007
On 4/23/07, Dario Lesca <d.lesca at solinos.it> wrote:
> Hi, how to found into string 2 or more word, only if are all present?
>
> % echo "aa bb cc dd"|egrep -q '(bb|dd)' && echo found
>
> This command show "found" if bb OR dd are in string.
> But if I want show "found" only if bb AND dd are present into string.
>
> What egrep (or sed) command I must use?
>
> Many thanks for your reply!
>
> --
> Dario Lesca <d.lesca at solinos.it>
>
> --
> fedora-list mailing list
> fedora-list at redhat.com
> To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
>
Will this do?
echo "aa bb cc dd" | grep bb | grep -q dd && echo found
Not as clean because you are calling two greps instead of one. But it
do what you seem to want to do. You can't use the -q on the first
grep pipe because you need that output to feed into the second grep
pipe.
I don't know perl well at all so can't give input on that solution
other than when I tested it with only one matching expression (i.e.
echo "aa bb cc ed"), it still came back as found. I have a perl book
and had a quick look to see if I could figure it out but no such luck.
Jacques B.
More information about the fedora-list
mailing list