Я ищу способ удалить только последний символ табуляции из вектора 1xN. Функция вычисляет среднее значение матрицы и печатает результат в 1 строку.
Я не могу использовать awk, sed, tcl, bc, perl и языки Python
Я пробовал оператор if и цикл while, используя следующий код.
if [[ line[-1] ]]
Моя функция ниже.
mean() {
input="${1:-/dev/stdin}" #input variable equal to file or text from stdin
transpose $input > tempmeanfile #call transpose function and place results in temp file
while read -a line #while loop reads the entire file
do
count=0 #count variable holds the rows count
sum=0 #sum variable holds the tallied sum
mean=0
for i in "${line[@]}" #for loop loops through the rows
do
((sum += $i)) #each number in the row is summed, left with one column
((count++)) #rows are incremented
done
((mean = sum/count)) #mean is set equal to the sum divided by the number of rows
printf "$mean\t" #print mean values
done < tempmeanfile #while temp file has not been read
printf "\n" #print new line
}
Пример ввода [1 \ t2 \ t3 \ n4 \ t5 \ t6]
после вызова функции транспонирования [1 \ t4 \ n2 \ t5 \ n3 \ t6]
Пример вывода 2 \ t5 \ t9 \ t