How to compare floating variables , integer value expected?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to compare floating variables , integer value expected?
# 1  
Old 03-22-2012
How to compare floating variables , integer value expected?

I am running some commands and I am trying to get an output into a variable. I am having problem when I try to put that value in while loop, it says integer value expected. What's the best way to accomplish this


Code:
  remaining=$(symclone -sid XXX -f Clone_test query | grep MB | awk '{print $2}')
   y=1
   while [ "$remaining" -gt  "$y" ]
    do
     echo "$remaining MB's to be copied....." >> mylog
     sleep 10
   remaining=$(symclone -sid XXX -f Clone_test query | grep MB | awk '{print $2}')
    done


Last edited by Corona688; 03-22-2012 at 01:07 PM..
# 2  
Old 03-22-2012
Since you're using awk anyway, do everything in awk, because it supports floating point variables. Use awk's return status to tell the shell loop whether it finished.

Incidentally, since you're using awk, you don't need grep either, since awk can do the function of both.

Code:
while symclone -sid XXX -f Clone_test query | awk -v R="$y" '/MB/ { printf("%s/%s remaining\n", $2, R); exit($2 > $y)}'
do
        sleep 10
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Integer expression expected

Hello , This is the piece of the code which is giving me trouble if ;then exit_proc "${SOURCEDIR}/${OUT_FILE} does not exists or not readable" 2 else word_count=`wc -l < ${SOURCEDIR}/$OUT_FILE` fi if ;then exit_proc "Word_count is more than allowed limit" 1 else... (6 Replies)
Discussion started by: Sri3001
6 Replies

2. Shell Programming and Scripting

Integer expression expected

Hi, I have placed the script and running successfully on AIX However in Linux it throws integer expression expected Could some one please help me to fix this MaxThreshold4alert=`echo "$MaxCapacitycnt*(80/100)" |bc -l` echo $MaxThreshold4alert Error: 40.00000000000000000000: integer... (2 Replies)
Discussion started by: ajothi
2 Replies

3. Shell Programming and Scripting

Integer expression expected

Newb here echo "$yesterdaysclose" echo "$close" if ; then echo "stocks moving up" elif ; then echo "stock is moving down" else echo "no change" fi seems to evaluate the floating decimal correctly however returns ./shellscript1.sh: line 17: [: : integer expression expected... (3 Replies)
Discussion started by: harte
3 Replies

4. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

5. UNIX for Dummies Questions & Answers

Integer Expression Expected!?!?

Ok, so I am beggining a script to factor the time difference from when a user logs on to current time but before I can even get too far I am getting the INTEGER EXPRESSION EXPECTED error. Can someone tell me what I am doing wrong? lhour=$(who | grep "$1" | cut -c30,31); lmin=$(who | grep "$1"... (1 Reply)
Discussion started by: losingit
1 Replies

6. Shell Programming and Scripting

:integer expression expected

Hi, echo $i until || do read NUM if && ; then printf "$FBOLD\nInvalid number, please enter valid backup number: $FREG" fi done Getting below error : ./import_location.sh: line 234: [: : integer expression expected ./import_location.sh: line 234: [: :... (5 Replies)
Discussion started by: milink
5 Replies

7. Shell Programming and Scripting

Floating point to integer in variable length lines

Hi ! I'm looking for a way to transform certain floating point numbers in a one-line, variable length file to integers. I can do this in a crude way with sed : sed -e 's/0\.\(\):/\1:/g' -e 's/0\.0\(\):/\1:/g' -e 's/1\.000:/100:/g' myfile ... but this doesn't handle the rounding correctly. ... (3 Replies)
Discussion started by: jossojjos
3 Replies

8. UNIX for Dummies Questions & Answers

Check if input is an integer or a floating point?

Hiii I actually intent to check the integer or floating point number input by user i.e. 23, 100, 55.25, 12.50 ..etc. However, when someone input strings or alpha character, my program has to show invalid input.!! Is there any Unix shell script syntax can help me to check ? Thanking you (2 Replies)
Discussion started by: krishnampkkm
2 Replies

9. Shell Programming and Scripting

HELP: compare floating point variables??

Hi All, I got this script that pulls the Amps value from our RPC's , I basiclly want to compare the valued with a "limit" value -- if the numbers match or are greater than the definded value ...do something. My problem is I cant seem to figure out how to compare floating points... here is... (1 Reply)
Discussion started by: zeekblack
1 Replies

10. Shell Programming and Scripting

Replace floating-point by integer in awk

Hi, I am trying to write a script to extract multiple sets of data from a chemistry output file. The problem section is in the following format... Geometry "geometry" -> "geometry" 1 Pd 46.0000 -0.19290971 0.00535260 0.02297606 2 P ... (7 Replies)
Discussion started by: smadonald1
7 Replies
Login or Register to Ask a Question