Re: egrep and conditions
- From: James Waldby <not@xxxxxxxxxxxxx>
- Date: Wed, 4 May 2011 16:03:57 +0000 (UTC)
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 hihi
--
jiw
.
- References:
- egrep and conditions
- From: JAW
- Re: egrep and conditions
- From: pk
- egrep and conditions
- Prev by Date: Re: egrep and conditions
- Next by Date: Re: egrep and conditions
- Previous by thread: Re: egrep and conditions
- Next by thread: Re: egrep and conditions
- Index(es):
Relevant Pages
|