title: how to read a table in a text file column wise in bash
body: <p>I am very new to bash scripting and today I have worked on a problem which I generally do  it in python. The problem is I have a text file which is like this: (numbers in the row are separated by tabs)</p>
  
  <pre><code>1   1   1   1   1
  9   3   4   5   5
  6   7   8   9   7
  3   6   8   9   1
  3   4   2   1   4
  6   4   4   7   7
  </code></pre>
  
  <p>Now I have written a bash script which reads row by row and calculates row average and median for the row. Now I want to calculate the column average and column  median. how can I do this I am finding it difficult to read it column wise. <strong>I don't want to use awk</strong> this is my code:</p>
  
  <pre><code>#! /bin/bash
  clear
  if [ "$#" -eq 0 ]; then
      echo "Please provide arguments"
  elif [ "$#" -lt 2 ]; then
       echo "You have to provide 2 arguments"
  elif [ "$#" -gt 2 ]; then
      echo "You have provided more number of arguments"
  else
      echo "You have entered correct number of arguments"
  fi
  option="${1}" 
  case ${option} in 
     -rows| -r) FILE="${2}"
        echo "rows" 
        echo "File name is $FILE"
        clear
        echo "Average Median"
        while read -r line
        do
        len=0
        tot=0
        name=$line
        IFS=' ' read -a array &lt;&lt;&lt; "$name"
        for element in "${array[@]}"
        do
            tot=$(expr $tot + $element)
            #let tot+=$element #you can use this as well to get the totals
            let len+=1
        done
        avg= printf "%.0f" $(echo "scale=2;$tot/$len" | bc)
        readarray -t sorted &lt; &lt;(for a in "${array[@]}"; do echo "$a"; done | sort)
        no=`expr $len % 2`
        if [ $no -eq 0 ]; then
        mid=`expr $len / 2`
        echo "$avg   ${sorted[$mid]}"
        else
        mid=`expr $len / 2`
        echo "$avg   ${sorted[$mid]}"
        fi
        unset "array[@]"
        unset "sorted[@]"
        done &lt; "$FILE"
        ;; 
     -cols| -c) FILE="${2}" 
        echo "cols"
        echo "File name is $FILE"
        while read line
        do
        x=1
        read -a array &lt;&lt;&lt; "$line"
        for element in "${!arra[@]}"
        do
        row[${element}] = $((${row[${element}]}+${array[$element]}))
        ((x++))
        done
        done &lt; "$FILE"
        for element in ${row[@]}
        do
        mean=$(echo "$element/$x" bc -l)
        echo "$element / $x = $mean"
        done
        ;; 
     *)  
        echo "`basename ${0}`:usage: [-r|-rows rows] | [-c|-cols columns]" 
        exit 1 # Command to come out of the program with status 1
        ;; 
  esac 
  
  Can anyone help me with this please
  </code></pre>