| 1 |
#!/bin/awk -f |
| 2 |
BEGIN { |
| 3 |
# How many lines |
| 4 |
lines=0; |
| 5 |
total=0; |
| 6 |
} |
| 7 |
{ |
| 8 |
# this code is executed once for each line |
| 9 |
# increase the number of files |
| 10 |
lines++; |
| 11 |
# increase the total size, which is field #1 |
| 12 |
total+=$1; |
| 13 |
} |
| 14 |
END { |
| 15 |
# end, now output the total |
| 16 |
print lines " lines read"; |
| 17 |
print "total is ", total; |
| 18 |
if (lines > 0 ) { |
| 19 |
print "average is ", total/lines; |
| 20 |
} else { |
| 21 |
print "average is 0"; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
#From https://www.grymoire.com/Unix/Awk.html |