From: Steven Baltakatei Sandoval Date: Tue, 20 Feb 2024 22:06:07 +0000 (+0000) Subject: feat(unitproc/bkt-decimate):Add Bash function to decimate stdin X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/db51b505288f4060d8a3de1ed419263b50428e51?ds=inline feat(unitproc/bkt-decimate):Add Bash function to decimate stdin --- diff --git a/unitproc/bkt-decimate b/unitproc/bkt-decimate new file mode 100644 index 0000000..47db83f --- /dev/null +++ b/unitproc/bkt-decimate @@ -0,0 +1,23 @@ +#!/bin/bash + +decimate() { + # Desc: Randomly remove 10% of stdin lines + # Depends: GNU Coreutils 8.32 (shuf) + # Version: 0.0.1 + + # Read lines + mapfile -t lines; + + # Calc lines to keep, lk + lc="${#lines[@]}"; + lk="$((lc * 900 / 1000))"; + + printf "%s\n" "${lines[@]}" | \ + nl -w1 -s' ' | \ + shuf | \ + head -n "$lk" | \ + sort -n -k1,1 | \ + cut -d' ' -f2- ; +}; # randomly eliminate 10% of lines + +echo "$WARNING:This is a Bash function definition."