#!/bin/bash decimate() { # Desc: Randomly remove 10% of stdin lines # Depends: Bash 5.1.16; GNU Coreutils 8.32 (shuf, nl, head, sort, cut) # Version: 0.0.1 # Read lines mapfile -t lines; # Calc lines to keep, lk lc="${#lines[@]}"; lk="$((lc * 900 / 1000))"; # Output 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."