Given a file with an input in the format of (longitude,latitude,date,time,temperature), write a bash script that returns the place and time of the highest measured temperature on the list.
Example input:
53.0382,96.5753,2010.11.16.,07:23,38
53.0382,96.5753,2000.06.21.,09:05,-16
53.0382,96.5753,2007.05.16.,02:00,-4
53.0382,96.5753,2008.07.27.,22:38,-6
53.0382,96.5753,2001.07.09.,09:50,-12
53.0382,96.5753,2016.12.08.,22:55,28
Example output:
The highest measured temperature was 38 degrees on 2010.11.16. at 07:23. it was measured at the coordinates of 53.0382, 96.5753
I've written a script that successfully takes the input and splits it into different arrays for each of the different values given. I was trying to loop through the temperatures to find the index of the highest one, using it to index the date,time,and location arrays for the output.
#!/bin/bash
latitude=(); longitude=(); date=(); time=(); value=();
while IFS=, read -ra arr;
do
latitude+=(${arr[0]})
longitude+=(${arr[1]})
date+=(${arr[2]})
time+=(${arr[3]})
value+=(${arr[4]})
done < temperatures.txt
max=0
maxI=0
count=$(wc -l <temperatures.txt)
for ((i=0; i<$count; i++)) ;
do
echo ${value[i]}
if ((${value[i]} > $max)) ; then
max=${value[i]}
maxI=$i
fi
done
echo $max
echo $maxI
With the above code, I get the error syntax error: invalid arithmetic operator (error token is " > 0"). It seems to be a problem with line 17, the if statement. I'd appreciate it if anyone could shed some light on what my problem is.
time.echo i=$i and \${value[$i]}=${value[i]and you may see what your problem is. Good luck.`temperatures.txtfor malformed field 5, such as an extra comma, space or trailing dot.max=38 ; maxI=0, so perhaps an issue with original code or data file? from a debugging point of view, addset -xv(enable debug mode) at the beginning of the script, run the script, review the output for unexpected variable assignments; alternatively, cut-n-paste your actual code into shellcheck.net to see if there are any syntax issues (with your actual code)