Grep on multiple lines

I 'm trying to grep 2 fieldds on 2 differnt lines. Like this:

psit > file

egrep -e '(NS|ES)' $file. Not working. If this succeeds then run next cmd else exit. Pls Help

Gundu

what's the output of 'psit'?

it has the output like this :

Active servers at node ***.***.***.com are :
Name Marker Code Comms Port Launch PerClient? OS-pid
------------------------------------------------------------------------------
NS * cdr tcp **** manual --- -8892649
24

NPSession19 * xdr tcp **** manual --- 16285
AVSessionFactoryServer* xdr tcp **** manual --- -8892597
73
SYCorbaDispatcher* xdr tcp **** manual --- 10347
ES * cdr tcp **** manual --- 8989
~
~
~

ok, this grep works. what seems to be the problem?
do you need to 'succeed' ONLY if BOTH fields are found? And 'fail' otherwise?

Hope you need this:

if [ `egrep -c -e "ES|NS" $file` -gt 0 ];then
echo sucess
else
echo exittt
fi

bash:
(egrep "ES|NS" filename) && { echo "ok"; } || { echo "sorry"; }

When I run the script, it is waiting and not giving me prompt back. Not sure what is wrong here.

psit >file

if [ `egrep -c -e "ES|NS" $file` -gt 0 ];then
echo sucess
else
echo exittt
fi

Gundu


if [ `psit | egrep -c -e "ES|NS"` -gt 0 ]; then
   echo sucess
else
   echo exittt
fi

Hi,

this works fine:
if [ `psit | egrep -c -e "ES|NS"` -gt 0 ]; then
echo sucess
else
echo exittt
fi

I was revisited this script and added some more lines like:

if [ `SYnpt | egrep -c -e "system|not running"` -gt 0 ]; then
echo Start Server
else
echo Success
fi

SYnpt output is : system is not running
it is always picking success. Not sure why??

Thanks,
Gundu

Hi,

Need help on this part:

if [ `SYnpt | egrep -c -e "system|not running"` -gt 0 ]; then
echo Start Server
else
echo Success
fi

SYnpt output is : system is not running
it is always picking success. Not sure why??

Thanks,
Gundu

I changed your script as follows .. and it is working fine


if [ `echo "system is not running" | egrep -c -e "system|not running"` -gt 0 ]; then
	echo "start server"
else
	echo "Success"

fi

This code is picking "start Server" even the system is running

if [ `echo "system is not running" | egrep -c -e "system|not running"` -gt 0 ]; then
echo "start server"
else
echo "Success"

fi

I need to write this based on SYnpt output, which is

SYnpt
system is running

or
SYnpt
system is not running

Thanks,
Gundu

if [ `psit | grep -c not` -gt 0 ] ; then
   echo "start server"
else
   echo "system is running"
fi

Thanks, it is working

Gundu