variable= 'cat file|wc -l' String problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting variable= 'cat file|wc -l' String problems
# 1  
Old 07-08-2005
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
# 2  
Old 07-08-2005
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 11:36 AM.. Reason: now tested
# 3  
Old 07-08-2005
Try to Get rid of the * in front of the 0 and 1 and see if that works.
# 4  
Old 07-08-2005
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Trying to cat a file that is a variable

Thank you in advance for looking at this, I've scoured the internet and can't find the answer I'm looking for!! - I am new at bash script so please bare with me!! I have a script where I've identified individual files within a folder, the filename is then stored as a variable ($filename):... (3 Replies)
Discussion started by: paperbackwriter
3 Replies

2. UNIX for Dummies Questions & Answers

How to append a string by cat and redirect to other file?

Hi, when I do cat for kernel parameters cat /proc/sys/kernel/sem >> /etc/sysctl.conf 4096 4096 32 128 The above command working with out any doubt but I want to pass it like below, need to append "kernel.sem =" and pass it to /etc/sysctl.conf kernel.sem = 4096... (2 Replies)
Discussion started by: stew
2 Replies

3. UNIX for Dummies Questions & Answers

Grep or cat The Whole Directory PROBLEMS :(

Hi Guys This is my first post so I am not sure how things go here. I'm sorry if I'm breaking the rule or something. Feel free to correct me about that :) So as I was saying... I'd been trying to grep this folder containing 900,000 txt files but seems no luck. I get either "No such file... (6 Replies)
Discussion started by: Nexeu
6 Replies

4. Shell Programming and Scripting

cat file with variable substitution

MyFile contains: ALTER TABLE $DBN.$TBN ADD $COL $TYP COMPRESS ($VAL); I need to cat the file and have it substitute all of the variables with their contents. cat MyFile does not work. The following works for the first line, but errors on the second line because of the paren: $ while read... (2 Replies)
Discussion started by: Phil27577
2 Replies

5. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

6. Shell Programming and Scripting

Problems assigning a string to a variable

Hello everyone, My problem looks quite simple , how to assign a string with spaces and lines "\n" to a variable. I've tried all kind of quoting and is impossible, bash always try to execute the string and never executes a simple assignation. This is part of the code ... (1 Reply)
Discussion started by: trutoman
1 Replies

7. Shell Programming and Scripting

Problems on cat and substring replacement, shell

Hi I'm new in the Shell world, and I've been trying the whole day to get my script to work. I'm under Ubuntu 10.04. Let me explain: I want to list all the files matching some regex in a directory, and then make some some string replacement on the name of the files, and then a cat on the... (2 Replies)
Discussion started by: albh
2 Replies

8. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

9. Shell Programming and Scripting

cat vs head vs readline get variable from txt file

I have a file with a single filename in it, which I want to assign to a BASH variable, so I've been trying: c=$(head -1 somefile) echo $c which outputs correctly, but them when I do ... somecommand $c it says it can't find the file, is that because it's grabbing the whole line, and... (5 Replies)
Discussion started by: unclecameron
5 Replies

10. UNIX for Dummies Questions & Answers

Using a variable inside a file to cat another.

I have a question to do and it's somewhat confusing. It says, and I quote "Create a file called file_1 with three lines of text in it. Create a shell variable called "f_name", assign it the string "file_1". Use the cat command and the variable "f_name" to display the contents of the file... (3 Replies)
Discussion started by: MaestroRage
3 Replies
Login or Register to Ask a Question