Regex '&' operator

Regex '&' operator

Post by Damian Ibbotso » Sat, 25 Jan 2003 01:46:18



Is there an AND operator that can be used in regular expressions?

If I have a file as below...

file
----
big bad ugly
ugly big bad
big
bad
ugly

.. how can I extract the lines that contain all of {big, bad, ugly}?

I know I could do this by piping the result of one grep into another,
but can it be done in one go?

--
Posted via http://dbforums.com

 
 
 

Regex '&' operator

Post by Peter J. Ackl » Sat, 25 Jan 2003 03:35:26



> Is there an AND operator that can be used in regular expressions?

> If I have a file as below...

> file
> ----
> big bad ugly
> ugly big bad
> big
> bad
> ugly

> .. how can I extract the lines that contain all of {big, bad, ugly}?

> I know I could do this by piping the result of one grep into another,
> but can it be done in one go?

  egrep 'big.*(bad.*ugly|ugly.*bad)|bad.*(big.*ugly|ugly.*big)|ugly.*(big.*bad|bad.*big)'

Peter

--
I wish dialog boxes had a butten saying "Whatever".  I hate being
forced to answer "Yes" or "No" to a question I have no opinion on
whatsoever.  There ought to be a button matching my indifference.

 
 
 

Regex '&' operator

Post by Ben » Sat, 25 Jan 2003 03:43:54




>>Is there an AND operator that can be used in regular expressions?

>>If I have a file as below...

>>file
>>----
>>big bad ugly
>>ugly big bad
>>big
>>bad
>>ugly

>>.. how can I extract the lines that contain all of {big, bad, ugly}?

>>I know I could do this by piping the result of one grep into another,
>>but can it be done in one go?

>   egrep 'big.*(bad.*ugly|ugly.*bad)|bad.*(big.*ugly|ugly.*big)|ugly.*(big.*bad|bad.*big)'

But that's big bad and ugly...

:-)
Ben

 
 
 

Regex '&' operator

Post by Barry Margoli » Sat, 25 Jan 2003 04:01:21






>>>Is there an AND operator that can be used in regular expressions?
>>   egrep
>'big.*(bad.*ugly|ugly.*bad)|bad.*(big.*ugly|ugly.*big)|ugly.*(big.*bad|bad.*big)'

>But that's big bad and ugly...

And as the number of strings you need to match grows, the size of the
regexp grows exponentially.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Regex '&' operator

Post by John W. Krah » Sat, 25 Jan 2003 09:31:23



> Is there an AND operator that can be used in regular expressions?

> If I have a file as below...

> file
> ----
> big bad ugly
> ugly big bad
> big
> bad
> ugly

> .. how can I extract the lines that contain all of {big, bad, ugly}?

> I know I could do this by piping the result of one grep into another,
> but can it be done in one go?

perl -ne'print if /big/ and /bad/ and /ugly/' file

John
--
use Perl;
program
fulfillment

 
 
 

Regex '&' operator

Post by John DuBo » Sat, 25 Jan 2003 09:44:46




Quote:

>Is there an AND operator that can be used in regular expressions?

>If I have a file as below...

>file
>----
>big bad ugly
>ugly big bad
>big
>bad
>ugly

>.. how can I extract the lines that contain all of {big, bad, ugly}?

>I know I could do this by piping the result of one grep into another,
>but can it be done in one go?

If you have agrep:

agrep -w 'big;bad;ugly'

In agrep, ';' means "and", and -w means "whole word match only".

        John
--

 
 
 

Regex '&' operator

Post by Tapani Tarvaine » Sat, 25 Jan 2003 18:05:38



> .. how can I extract the lines that contain all of {big, bad, ugly}?

> I know I could do this by piping the result of one grep into another,
> but can it be done in one go?

awk '/big/ && /bad/ && /ugly/'

--
Tapani Tarvainen

 
 
 

Regex '&' operator

Post by Tim Cargi » Sat, 25 Jan 2003 20:16:15



> Is there an AND operator that can be used in regular expressions?

> If I have a file as below...

> file
> ----
> big bad ugly
> ugly big bad
> big
> bad
> ugly

> .. how can I extract the lines that contain all of {big, bad, ugly}?

> I know I could do this by piping the result of one grep into another,
> but can it be done in one go?

After 'egrep' there is always 'fgrep -f file', but it means having
a 'pattern file' (file)* around.  It's useful for a LARGE
number of patterns, but there could be a limit.

HTH

Tim

 
 
 

Regex '&' operator

Post by Tapani Tarvaine » Sat, 25 Jan 2003 22:03:11




> > .. how can I extract the lines that contain all of {big, bad, ugly}?
> After 'egrep' there is always 'fgrep -f file', but it means having
> a 'pattern file' (file)* around.  It's useful for a LARGE
> number of patterns, but there could be a limit.

The patterns in the file are treated as alternatives, i.e., ORed
instead of ANDed as OP wanted.

--
Tapani Tarvainen

 
 
 

Regex '&' operator

Post by Tim Cargi » Sun, 26 Jan 2003 10:23:00





> > > .. how can I extract the lines that contain all of {big, bad, ugly}?

> > After 'egrep' there is always 'fgrep -f file', but it means having
> > a 'pattern file' (file)* around.  It's useful for a LARGE
> > number of patterns, but there could be a limit.

> The patterns in the file are treated as alternatives, i.e., ORed
> instead of ANDed as OP wanted.

Correct.  It should have been 'egrep -f file < search_file' for Ored.
Avoiding this approach altogether is best, isn't it?
 
 
 

Regex '&amp;' operator

Post by laura fairhe » Mon, 27 Jan 2003 18:05:17




Quote:

>Is there an AND operator that can be used in regular expressions?

Not using the standard ERE/BRE regular expressions. Perl regular
expressions allow it thou`.

Quote:>If I have a file as below...

>file
>----
>big bad ugly
>ugly big bad
>big
>bad
>ugly

>.. how can I extract the lines that contain all of {big, bad, ugly}?

>I know I could do this by piping the result of one grep into another,
>but can it be done in one go?

You can do it with 'sed' in one go;

sed -e '/big/!d' -e '/bad/!d' -e '/ugly/!d' file.in

Quote:

>--
>Posted via http://dbforums.com

wishesfrom
laura

--
alt.fan.madonna |news, interviews, discussion, writings
                |chat, exchange merchandise, meet fans....
                |Get into the groove baby you've got to... check us out!

 
 
 

Regex '&amp;' operator

Post by John Savag » Wed, 29 Jan 2003 09:36:29



>> .. how can I extract the lines that contain all of {big, bad, ugly}?

>> I know I could do this by piping the result of one grep into another,
>> but can it be done in one go?

>awk '/big/ && /bad/ && /ugly/'

Not to overlook sed for the task, and I'll assume the strings are words:

sed -n '/\<[Bb]ig\>/{/\<[Bb]ad\>/{/\<[Uu]gly\>/p;};}' data

or,

sed '/\<[Bb]ig\>/!d;/\<[Bb]ad\>/!d;/\<[Uu]gly\>/!d' data
--
John Savage            (for email, replace "ks" with "k" and delete "n")

 
 
 

Regex '&amp;' operator

Post by Tim Cargi » Thu, 30 Jan 2003 00:08:42





> >Is there an AND operator that can be used in regular expressions?

> Not using the standard ERE/BRE regular expressions. Perl regular
> expressions allow it thou`.

> You can do it with 'sed' in one go;

> sed -e '/big/!d' -e '/bad/!d' -e '/ugly/!d' file.in

Have you been* out with Dr. Liu?
You've got to at least somehow get this into a sed loop.
Too many -e's!  :-)

- Show quoted text -

Quote:

> >--
> >Posted via http://www.veryComputer.com/

> wishesfrom
> laura

 
 
 

1. Want bash '&' to behave like csh '&'

Is there some way to make the bourne-ish shells ("bash" in
particular) behave like the csh-ish shells with respect to
how they handle jobs backgrounded with a '&'?  Bourne shells
kill all their backgrounded children when the shell dies,
and C shells leave backgrounded jobs running when the shell
dies.  I already know about nohup, but that's not an elegant
solution for our needs.  I'd like to make it work with just '&'.

(Background for why we want this...)

I've got a group of users who are mildly familiar with Unix (can
use ls, cp, rm, mv, et all, but that's about it.)

They currently use tcsh as their default shell and I want to
switch them to bash because its better for scripting, and I
don't have time anymore to maintain two sets of default login
scripts for all our settings (bourne and csh versions).

Anyway, I have seen that most of the functionality of tcsh they
use is also there in bash, so it should be smooth except that they
tend to background jobs alot with '&' for X11 programs started
from an xterm.
--

2. RealPlayer 8 won't start

3. &&&&----Looking for a unix shell------&&&&&

4. Is rwall the good tool ?

5. ppp && PPPoE && ADSL && net && buffer(s)

6. trouble with ethernet

7. &#27809;&#26377;&#20154;&#29992;&#20013;&#25991;&#21527;&#65311;

8. LU6.2

9. Why does SunOS crash for '(cmd &) >& /dev/null'?

10. ``red-zone'' memory protection/mmap && munmap

11. rsh machine -n 'command >&/dev/null </dev/null &'

12. How to get 'regex()' or 're_exec()''s source?

13. ``red-zone'' memory protection/mmap && munmap