Re: If with multiple greps

From: William Park (opengeometry_at_yahoo.ca)
Date: 12/02/03


Date: 2 Dec 2003 06:24:50 GMT

greyfell@zerobyte.org wrote:
> I would like to use an if with more than one grep in it. Basically, I
> have this statement that works:
>
> if grep -F -q "$ALIASIP " /etc/hosts
>
> I would like to make it compound so that either of two greps will
> result in a true and drop into the then. I'd like to do basically...
>
> if [ `grep -F -q "$ALIASIP " /etc/hosts` -o `grep -F -q "$ALIASIP\t"
> /etc/hosts` ]
>
> That doesn't seem to work, though. It always tests true, and I'm not
> quite certain why. I know other ways I can get this to work, but if I
> keep falling back on the proverbial long way around, I'll never get
> any better at this. Any help appreciated.

Since your logic is OR,
    if grep -F -e "aaa" -e "bbb" ... ; then ... ; fi
Also, you can write the patterns to a file, and
    if grep -F -f file ; then ... ; fi

-- 
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution for data management and processing. 


Relevant Pages

  • Re: find strings in sub directories
    ... > How do I find a specific string with grep in all files including ... > files in sub directories? ... Linux solution for data management and processing. ...
    (comp.unix.shell)
  • Re: If with multiple greps
    ... > I would like to make it compound so that either of two greps will ... It always tests true, and I'm not ... Maybe you meant to use the "-x" grep option? ...
    (comp.unix.shell)
  • Re: If with multiple greps
    ... It always tests true, and I'm not ... grep -F is the wrong tool. ... The inner pair of square brackets contains a space and a tab. ... Thanks to Nigeria, any email with the word "urgent" in the subject or address will be deleted. ...
    (comp.unix.shell)
  • If with multiple greps
    ... I would like to use an if with more than one grep in it. ... I would like to make it compound so that either of two greps will ... It always tests true, and I'm not ... keep falling back on the proverbial long way around, ...
    (comp.unix.shell)
  • Re: If with multiple greps
    ... > I would like to use an if with more than one grep in it. ... > I would like to make it compound so that either of two greps will ... It always tests true, and I'm not ... > keep falling back on the proverbial long way around, ...
    (comp.unix.shell)