Get value from file!!!!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Get value from file!!!!
# 8  
Old 05-02-2007
See if this would do it for you:
Code:
FirstNumber=`uptime | sed -e 's/.*average://' -e 's/ //g' | cut -d',' -f1`
echo $FirstNumber

# 9  
Old 05-02-2007
I am able to get the load average as u said. But i am not able to compare to a number. When i give like

FirstNumber=`uptime | sed -e 's/.*average://' -e 's/ //g' | cut -d',' -f1`
echo $FirstNumber

if [ $FirstNumber -gt 77 ]; then
echo "Greater than 77"
else
echo "Less or equal to 77"
fi



I get an error

0.34
./test2: line 3: [: 0.34: integer expression expected
Less or equal to 77


I think it needs to converted to an integer
# 10  
Old 05-02-2007
Jibu,
Shell does not handle arithmetics nor comparisons with decimal numbers.
What other value do you want to compare it with?
# 11  
Old 05-02-2007
MySQL

I have found a way to do it. I know this is not the right way. But it works!!!!

uptime|gawk -F" " '{ print $8 }'|gawk -F , '{ print $1 }'|gawk -F . '{ print $1 }'> load
while read Inbr
do
echo $Inbr
if [ $Inbr -gt 77 ]; then
echo "Greater than 77"
else
echo "Less or equal to 77"
fi
done < load


Thanks for all the help!!!! Smilie
# 12  
Old 05-02-2007
Jibu,
Again, shell does not handle arithmetics nor comparisons with decimal numbers.
The following code:
Code:
test_var() {
if [ $1 -lt 77 ]; then
 echo "$1 is less than 77"
else
 if [ $1 -eq 77 ]; then
   echo "$1 is equal 77"
 else
   echo "$1 is greater than 77"
 fi
fi
}

test_var 76.8
test_var 77.0
test_var 77.8

Gives the following output:
76.8 is less than 77
77.0 is equal 77
77.8 is equal 77
# 13  
Old 05-02-2007
Java

I'm clear with that part now. I removed the decimal points using gawk itself and made it an integer. Now my problem is that i have a file called flag which would be having the values 1 or 0 indicating that the server is already stopped or not so. It is used along with the if condition so that i need not stop an already stopped server. I need to get the value in the text file to a variable in the script. Is it possible????
# 14  
Old 05-03-2007
Quote:
I need to get the value in the text file to a variable in the script. Is it possible????
Jibu,
This question has been answered explicitly in my #4 reply in this post.
*** Comment removed, rules 1 and 2 ---reborg

Last edited by reborg; 05-03-2007 at 11:42 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies
Login or Register to Ask a Question