Re: egrep and conditions



On Wed, 04 May 2011 14:40:28 +0100, pk wrote:
On Wed, 04 May 2011 06:32:42 -0700, JAW wrote:
The below example basically returns a zero return code when I get
offset or gov.

I am looking to get a zero return code only if offset and gov are in
the display

ntpq -p | egrep -e "offset|gov";echo $?

Basically instead of conditional OR I am looking for a conditional AND.

Note to OP: All instances of "basically" and "conditional" in your post
appear to be superfluous. OR and AND are functions of conditions. If
you really mean to refer to conditional functions of conditions, you will
have to define those functions explicitly.

egrep -e 'offset.*gov|gov.*offset'

or only one of the alternatives, depending on what exactly do you want.

Output of ntpq -p looks like (for example)
remote refid st t when poll reach delay offset jitter
==============================================================================
+pool-test.ntp.o 66.220.9.122 2 u 109 128 377 124.799 4.332 6.238
*andromeda.cs.pu .CDMA. 1 u 70 128 377 84.704 -5.402 7.158

so presumably the OP is looking for 'offset' in the title line and
'gov' in a server name. egrep looking at one line at a time can't
match both terms at once, but awk works ok. Eg:

ntpq -p | awk '/gov/{g=1} /offset/{f=1} END{exit f+g-2}' && echo hi

ntpq -p | awk '/dro/{g=1} /offset/{f=1} END{exit f+g-2}' && echo hi
hi

--
jiw
.



Relevant Pages

  • Re: egrep and conditions
    ... JAW wrote: ... The below example basically returns a zero return code when I get ... offset or gov. ...
    (comp.unix.shell)
  • egrep and conditions
    ... The below example basically returns a zero return code when I get ... offset or gov. ... the display ...
    (comp.unix.shell)
  • Re: egrep and conditions
    ... The below example basically returns a zero return code when I get ... offset or gov. ... ntpq -p | awk ' ...
    (comp.unix.shell)
  • Re: egrep and conditions
    ... On 5/4/2011 10:47 AM, Stephane CHAZELAS wrote: ... offset or gov. ... I am looking to get a zero return code only if offset and gov are in ...
    (comp.unix.shell)
  • Re: Boost process and C
    ... temperatures is nonsense, yet people do it all the time when ... zero address. ... and the same scale for the offset too. ...
    (comp.lang.c)