Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #! /bin/bash
  2. filename=$1
  3. input=${filename:-/dev/stdin}
  4.  
  5. colNum=1
  6.  
  7. while read myLine
  8. do
  9.  
  10. sorted_line=$(cut -f $colNum $input | sort -g)
  11.  
  12. echo $sorted_line
  13.  
  14. read -a medianArr <<< $sorted_line
  15.  
  16. middle=`expr ${#medianArr[@]} / 2`
  17.  
  18. median=${medianArr[$middle]}
  19.  
  20.  
  21. echo $median
  22.  
  23. colNum=`expr $colNum + 1`
  24.  
  25. done <${filename:-/dev/stdin}
  26.  
  27. % ./median test_file
  28.  
  29. % cat test_file | ./median
  30.  
  31. 1
  32. 9
  33. 6
  34. 3
  35. 3
  36. 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement