Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Read multiple lines from input.
- #!/bin/bash
- #Process command line options
- while getopts "r" opt ;do
- if [[ $opt == 'r' ]] ;then
- flagTrue=1
- else
- flagTrue=0
- fi
- done
- shift
- while read line ; do
- if [[ $flagTrue == 1 ]] ; then
- while read one tail ; do
- echo "$one"
- count=0
- for a in $tail ; do
- linesum=$(($linesum + $a))
- count=$(($count + 1))
- done
- echo $linesum $count $one | awk '{ print $3 " " int(($1/$2)+0.5) }'
- linesum=0
- average=0
- done
- else
- while read one tail ; do
- count=0
- for a in $tail ; do
- linesum=$(($linesum + $a))
- count=$(($count + 1))
- done
- average=$(($linesum / $count))
- echo "$one $average"
- linesum=0
- average=0
- done
- fi
- done < "${1:-/dev/stdin}"
- # while getopts "r" opt ;do
- # if [ $opt == 'r' ] ; then
- # else
- # fi
- # done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement