I have a .txt file that has integer values written in it with a ";" separator.
117;92;16;20;
I need to compare these and select the highest one.
My code:
IFS=';' #Internat Field Separator
read -ra vector<$file
max=$vector[0]
min=$vector[0]
for i in ${vector[@]}
do
if [[ $i > $max ]] ; then
max=$i
fi
if [[ $i < $min ]] ; then
min=$i
fi
done
echo "Max value is $max, minimal value is $min"
break
The output is:
Max value is 92, minimal value is 16.
So of course this is wrong. When I try to echo it:
echo $value ( in a loop of course )
The output is
177[0] 92 16 25
Why does the first letter show as int[0]? Because of that I cannot compare them. I can't figure out anything...
max=${vector[0]}; min=${vector[0]}declare -p vector, by the way, is a best-practices way to print a fully known/knowable value for the variable by that name.python -c "import sys; print(max(int(i) for i in sys.stdin.readline().split(';')))" <yourfile