1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #!/bin/bash # # info: convert a preference profile where value is rank and position is candidate to a preference profile where position is rank and value is candidate #setup if [ $ # -ne 0 ]; then input=$1; else input=0; fi candidates=12 #loop through lines while read line; do #initialize newrank newrank= "" #loop through new positions for i in ` seq 1 $candidates`; do #variable to store position of a value pos=0 #loop through old values for value in $line; do #increment pos pos=$(($pos+1)) #old position becomes new value if old value is equal to new position #if [[ $value != [0-9]* ]]; then echo error; fi #check for errors in input if [ $value - eq $i ]; then newrank= "$newrank $pos" break ; else k=1; fi done done echo $newrank done <$input |