Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.98 KB | None | 0 0
  1. #!/bin/bash
  2. #Read multiple lines from input.
  3.  
  4.  
  5. #!/bin/bash
  6. #Process command line options
  7.  
  8. while getopts "r" opt ;do
  9.  
  10.         if [[ $opt == 'r' ]] ;then
  11.  
  12.             flagTrue=1
  13.         else
  14.             flagTrue=0
  15.         fi
  16. done
  17.  
  18. shift
  19.  
  20. while read line ; do
  21.  
  22.     if [[ $flagTrue == 1 ]] ; then
  23.  
  24.             while read one tail ; do
  25.                 echo "$one"
  26.                 count=0
  27.  
  28.                 for a in $tail ; do
  29.  
  30.                     linesum=$(($linesum + $a))
  31.                     count=$(($count + 1))
  32.  
  33.                 done
  34.                
  35.             echo $linesum $count $one | awk '{ print $3 " " int(($1/$2)+0.5) }'
  36.  
  37.             linesum=0
  38.             average=0
  39.        
  40.             done
  41.  
  42.     else
  43.  
  44.         while read one tail ; do
  45.             count=0
  46.            
  47.  
  48.             for a in $tail ; do
  49.                
  50.                 linesum=$(($linesum + $a))
  51.                 count=$(($count + 1))
  52.             done
  53.  
  54.             average=$(($linesum / $count))
  55.        
  56.             echo "$one $average"
  57.        
  58.             linesum=0
  59.            
  60.             average=0
  61.         done
  62.     fi
  63.  
  64. done < "${1:-/dev/stdin}"
  65.  
  66.  
  67.  
  68. # while getopts "r" opt ;do
  69.  
  70. #   if [ $opt == 'r' ] ; then
  71.  
  72.  
  73. #   else
  74.  
  75.  
  76. # fi
  77. # done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement