dsiggi
03-09-2008, 15:02
Servus,
ich brauch für ein Script, eine function die mir aus einer Reihe von Kommazahlen, die größte raussucht. Wie das ohne KOmmazahlen geht hab ich schon:
#!/bin/bash
tmp="/tmp/otrcut"
array1=3
rating1[0]=5.00
rating1[1]=6.00
rating1[2]=2.30
echo "Es wird die Cutlist mit der besten User-Bewertung heruntergeladen."
let array1--
while [ $array1 -ge 0 ]; do
rating1[$array1]=${rating1[$array1]%%.??}
echo "Rating ohne Komma: ${rating1[$array1]}"
let array1--
done
numvalues=${#rating1[@]}
for (( i=0; i < numvalues; i++ )); do
lowest=$i
for (( j=i; j < numvalues; j++ )); do
if [ ${rating1[j]} -ge ${rating1[$lowest]} ]; then
lowest=$j
fi
done
temp=${rating1[i]}
rating1[i]=${rating1[lowest]}
rating1[lowest]=$temp
done
bigest=${rating1[0]}
echo "Die beste Bewertung ist : $bigest"
cutlist_nummer=$(cat $tmp/search1.xml | grep "<rating>" | grep -n "<rating>$bigest" | cut -f1 | cut -d":" -f1)
echo "Es wird Cutlist Nummer $cutlist_nummer gealden."
id_cutlist=$(cat $tmp/search1.xml | grep "<id>" | head -n $cutlist_nummer | tail -n 1 | cut -d">" -f 2 | cut -d"<" -f 1)
echo "Die ID der Cutlist ist: $id_cutlist"
Wie schaff ich das nun, das auch die Zahlen hinter dem "." mit einbezogen werden? Über "-ge" gehts das ja nicht.
Danke für eure Hilfe.
dsiggi
ich brauch für ein Script, eine function die mir aus einer Reihe von Kommazahlen, die größte raussucht. Wie das ohne KOmmazahlen geht hab ich schon:
#!/bin/bash
tmp="/tmp/otrcut"
array1=3
rating1[0]=5.00
rating1[1]=6.00
rating1[2]=2.30
echo "Es wird die Cutlist mit der besten User-Bewertung heruntergeladen."
let array1--
while [ $array1 -ge 0 ]; do
rating1[$array1]=${rating1[$array1]%%.??}
echo "Rating ohne Komma: ${rating1[$array1]}"
let array1--
done
numvalues=${#rating1[@]}
for (( i=0; i < numvalues; i++ )); do
lowest=$i
for (( j=i; j < numvalues; j++ )); do
if [ ${rating1[j]} -ge ${rating1[$lowest]} ]; then
lowest=$j
fi
done
temp=${rating1[i]}
rating1[i]=${rating1[lowest]}
rating1[lowest]=$temp
done
bigest=${rating1[0]}
echo "Die beste Bewertung ist : $bigest"
cutlist_nummer=$(cat $tmp/search1.xml | grep "<rating>" | grep -n "<rating>$bigest" | cut -f1 | cut -d":" -f1)
echo "Es wird Cutlist Nummer $cutlist_nummer gealden."
id_cutlist=$(cat $tmp/search1.xml | grep "<id>" | head -n $cutlist_nummer | tail -n 1 | cut -d">" -f 2 | cut -d"<" -f 1)
echo "Die ID der Cutlist ist: $id_cutlist"
Wie schaff ich das nun, das auch die Zahlen hinter dem "." mit einbezogen werden? Über "-ge" gehts das ja nicht.
Danke für eure Hilfe.
dsiggi