The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to transform a string to a variable? Kerstin Shell Programming and Scripting 3 12-19-2007 08:46 AM
How to check a string in the variable josephwong Shell Programming and Scripting 1 06-25-2006 09:14 PM
problems egreging for a '(0)' string m223464 Shell Programming and Scripting 9 02-03-2006 09:51 AM
find: problems escaping printf-command string grahamb Shell Programming and Scripting 1 12-04-2005 01:00 PM
how to cut a string from a variable kjaisan UNIX for Dummies Questions & Answers 2 10-30-2003 10:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-08-2005
Registered User
 

Join Date: Jul 2005
Posts: 3
variable= 'cat file|wc -l' String problems

Hi,
does anybody knows about wc -l, how to transform it inot a just number?
this script ALWAYS executes the command3!!, However, the value of BMU_RUNNING is 1

case $BMU_RUNNING in
*0) command1
;;

*1) command 2;;


*)command 3;;
esac
The variable is
BMU_RUNNING=`more channels.dat|grep BMU |grep RUNNING|wc -l`
and it is equal to 1
echo $BMU_RUNNING is 1
but with set -x
+ + more channels.dat
+ grep BMU
+ grep RUNNING
+ wc -l
BMU_RUNNING= 1

thanks for your help
Santiago
Reply With Quote
Forum Sponsor
  #2  
Old 07-08-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
Can you try this
Code:
grep -c BMU_RUNNING channels.dat
instead of
Code:
grep |wc -l
combination?

Here's a test script:
Code:
#!/bin/sh

BMU_RUNNING=`grep -c BMU_RUNNING channels.dat`
case "$BMU_RUNNING" in
*0) echo it is "* zero";;
*1) echo it is "* one";;
*) echo it is "*";;
esac
and here's the test channels.dat file.
Code:
ASDJS
DBMU
BMU_RUNNING
AKLJFIDF
ASJDKSJD
It gave the expected output.

Last edited by blowtorch; 07-08-2005 at 07:36 AM. Reason: now tested
Reply With Quote
  #3  
Old 07-08-2005
Registered User
 

Join Date: Mar 2005
Posts: 22
Try to Get rid of the * in front of the 0 and 1 and see if that works.
Reply With Quote
  #4  
Old 07-08-2005
Registered User
 

Join Date: Jul 2005
Posts: 3
thanks blowtorch
that worked, I just modifiyes as my chnnels.dat file is something like:
CHANNEL(TO.BMUUZA1) STATUS(STOPPED)
CHANNEL(TO.YMQ2) STATUS(RUNNING)
CHANNEL(TO.BMUUZA1) STATUS(RUNNING)
CHANNEL(TO.YMQ1) STATUS(RUNNING)


to BMU_RUNNING=`grep BMU channels.dat|grep -c RUNNING`

case $BMU_RUNNING in
*0) echo `date`" WARNING, No Mainframe Channels TO.BMUAA1 are running "
echo " Please, start the channels or contact Mainframe transaction sy
stems team"
;;

*1) echo `date`" One Mainframe Channels TO.BMUAA1 not running "
echo " Please, start the channel or contact Mainframe transaction sys
tems team"
;;


*);;
esac

Thanks again so much
Santiago
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0