Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- filename=$1
- input=${filename:-/dev/stdin}
- colNum=1
- while read myLine
- do
- sorted_line=$(cut -f $colNum $input | sort -g)
- echo $sorted_line
- read -a medianArr <<< $sorted_line
- middle=`expr ${#medianArr[@]} / 2`
- median=${medianArr[$middle]}
- echo $median
- colNum=`expr $colNum + 1`
- done <${filename:-/dev/stdin}
- % ./median test_file
- % cat test_file | ./median
- 1
- 9
- 6
- 3
- 3
- 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement