I'm trying to get the difference between two numbers which I have taken from two files. I think my code will make sense:
I've tried to make it work by two different methods, didn't work. What I get as an output is zero (0).
#method 1
difference_btwn_eng_hrs_MX3_122=$(($(sed -n '1p' engine_hours_new_MX3_122.txt)-$(sed -n '1p' engine_hours_old_MX3_122.txt)))
echo "$difference_btwn_eng_hrs_MX3_122"
#method 2
new=$(sed -n '1p' engine_hours_new_MX3_122.txt)
old=$(sed -n '1p' engine_hours_old_MX3_122.txt)
echo "$new $old" | awk '{print $new - $old}'
Eventually I will use the difference to set intervals for email updates.
The values inside the files are 511.786 (new) and 509.768 (old), and the error I get from the terminal is as follows:
line 40: 511.786-509.765: syntax error: invalid arithmetic operator (error token is ".786-509.765")