data search either but not both

data search either but not both

Post by Wanda Roun » Wed, 16 Jan 2002 01:33:55



I needed to search data for one or the other term, but not both.

With this kind of data:

abc:def:ghi:jkl
abc:ghi:jkl:mno
ghi:jkl:mno:pqr
def:abc:jkl:ghi
def:abc:jkl:pqr
def:jkl:pqr:stu

Looking for abc or ghi, but not both, these work (same idea):
awk '!(/abc/&&/ghi/)' datafile|awk '(/abc/||/ghi/)'
egrep -v 'abc.*ghi|ghi.*abc' datafile |egrep "abc|ghi"

Is there anything awk or grep that is more concise? Any way to do it with sed?

Wanda Round

 
 
 

data search either but not both

Post by Kenny McCorma » Wed, 16 Jan 2002 02:00:51




Quote:>I needed to search data for one or the other term, but not both.

>With this kind of data:

>abc:def:ghi:jkl
>abc:ghi:jkl:mno
>ghi:jkl:mno:pqr
>def:abc:jkl:ghi
>def:abc:jkl:pqr
>def:jkl:pqr:stu

>Looking for abc or ghi, but not both, these work (same idea):
>awk '!(/abc/&&/ghi/)' datafile|awk '(/abc/||/ghi/)'
>egrep -v 'abc.*ghi|ghi.*abc' datafile |egrep "abc|ghi"

>Is there anything awk or grep that is more concise?

gawk '(/foo/)+(/bar/) == 1'

Now, the theoretically interesting question is: Why are the parens
necessary?

 
 
 

data search either but not both

Post by Ben.Altma » Wed, 16 Jan 2002 02:05:42



> I needed to search data for one or the other term, but not both.

> With this kind of data:

> abc:def:ghi:jkl
> abc:ghi:jkl:mno
> ghi:jkl:mno:pqr
> def:abc:jkl:ghi
> def:abc:jkl:pqr
> def:jkl:pqr:stu

> Looking for abc or ghi, but not both, these work (same idea):
> awk '!(/abc/&&/ghi/)' datafile|awk '(/abc/||/ghi/)'
> egrep -v 'abc.*ghi|ghi.*abc' datafile |egrep "abc|ghi"

> Is there anything awk or grep that is more concise? Any way to do it with sed?

    sed -n '{ /abc.*ghi/d; /ghi.*abc/d; /abc/p; /ghi/p; }' file
 
 
 

data search either but not both

Post by Wanda Rou » Sat, 19 Jan 2002 22:03:28





> >I needed to search data for one or the other term, but not both.

> >With this kind of data:

> >abc:def:ghi:jkl
> >abc:ghi:jkl:mno
> >ghi:jkl:mno:pqr
> >def:abc:jkl:ghi
> >def:abc:jkl:pqr
> >def:jkl:pqr:stu

> >Looking for abc or ghi, but not both, these work (same idea):
> >awk '!(/abc/&&/ghi/)' datafile|awk '(/abc/||/ghi/)'
> >egrep -v 'abc.*ghi|ghi.*abc' datafile |egrep "abc|ghi"

> >Is there anything awk or grep that is more concise?

> gawk '(/foo/)+(/bar/) == 1'

> Now, the theoretically interesting question is: Why are the parens
> necessary?

Thanks for the concise method.

So then
gawk '(/foo/)*(/bar/) == 1'
is the same as AND

and
gawk '(/foo/)*(/bar/) == 0'
will find either or neither but not both.

Wanda

 
 
 

1. Making search.domain.com goto a search page not main page.

Hello,

I am running Apache 1.3.4 on Linux. I have seen many pages with aliases in
front of the url (including the apache site). I am trying to make
http://search.trapped.tzo.com/ go to  a cgi-script, instead of the main
page. It took me quite a while, but I have found out how to do just about
everything I'd like to do with apache but this. I thought it may have to do
with Virtual Hosts, or maybe I just have to use a different syntax for the
Alias property?

Any help would be greatly appreciated Thanks in advance.

Joe Davis

http://trapped.tzo.com/

2. Quicken clone for Linux?

3. Xauth data does not match fake data?

4. rt6100

5. warning: X11 auth data does not match fake data

6. 2.4.21 troubles on a PWS

7. Large IDE drive problem

8. ISO9660 not there either...

9. MS serial mouse not working in either Slackware or Redhat; ISDN problem

10. wu-ftp does not allow anyone login from either local or remote

11. Either SMP or SCSI CDROM not both

12. POP server not allowing logins, either locally or from Win95 clients -- WHY?