Comparing variables in awk

I'm writing a shellscript that monitors the price of a watch. If the prices changes, it should email me. The body of the email will show the old price and the new price. However when I compare the two awk variables(oldprice and newprice) it always says they're not the same. The shellscript goes out and retrieves the web page source code, searches it for the price, once found it stores that price in the variable newprice. I then attempt to compare it to the old price, which comes from a file and is stored in the variable oldprice, but have problems there. I don't know if awk stores it as a string or as a float variable. I am also a little unsure about how to go about mailing myself when they are not the same. I'll appreciate any help you can give me.:b:

#!/bin/sh

wget -qO- http://cs.actx.edu/~craddock/unix2/lab11 | awk -v oldprice=`cat pricefile` '
    /<b class="price">/ {
    getline
    newprice = $0

    if (oldprice ~ newprice) {
        print "The price is the same"
    }
    else{
        print "The price is not the same"
        system ("mail -s"The price has changed" username")
        print newprice > "pricefile"
    }
}'

You did not inform us how you stored the oldprice in printfile. Assuming you stored it as a number i.e. 139.02 and not as $139.02, the following should work for you.

#!/bin/sh

wget -qO- http://cs.actx.edu/~craddock/unix2/lab11 | awk -v oldprice=`cat pricefile` '
    /<b class="price">/ {
    getline
    newprice = substr($0,2) + 0.00

    if (oldprice == newprice) {
        print "The price is the same"
    } else {
        print "The price is not the same"
    }
}'

Alright! I've got it figured out :slight_smile: Thanks for your help!