Skip to content

Instantly share code, notes, and snippets.

@fsteffenhagen
fsteffenhagen / stats.awk
Created November 19, 2021 09:30
Calculate simple stats for an unsorted input of numerical values using awk.
# stats.awk
# Calculate simple stats for an unsorted input of numerical values using awk.
# Prints the Count, Minimum, Maximum, Average, Median, Sum of the input values.
#
# Usage:
# > gen_random.sh | awk -f stats.awk
# Count: 100
# Min: 0.202
# Max: 1647.48
# Avg: 280.658
--[[
Conky, a system monitor, based on torsmo
Any original torsmo code is licensed under the BSD license
All code written since the fork of torsmo is licensed under the GPL
Please see COPYING for details
Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
@fsteffenhagen
fsteffenhagen / sum_filesize.sh
Last active April 15, 2024 10:04
sum human readable file sizes with numfmt and awk
# Input: list of rows with format: "<filesize> filename", e.g.
# filesizes.txt
#######################
# 1000K file1.txt
# 200M file2.txt
# 2G file3.txt
#
# Output:
cat filesizes.txt | numfmt --from=iec | awk 'BEGIN {sum=0} {sum=sum+$1} END {printf "%.0f\n", sum}'