doc(unitproc/bkt-decimate):Update depends comment
[BK-2020-03.git] / unitproc / bkt-decimate
1 #!/bin/bash
2
3 decimate() {
4 # Desc: Randomly remove 10% of stdin lines
5 # Depends: Bash 5.1.16; GNU Coreutils 8.32 (shuf, nl, head, sort, cut)
6 # Version: 0.0.1
7
8 # Read lines
9 mapfile -t lines;
10
11 # Calc lines to keep, lk
12 lc="${#lines[@]}";
13 lk="$((lc * 900 / 1000))";
14
15 printf "%s\n" "${lines[@]}" | \
16 nl -w1 -s' ' | \
17 shuf | \
18 head -n "$lk" | \
19 sort -n -k1,1 | \
20 cut -d' ' -f2- ;
21 }; # randomly eliminate 10% of lines
22
23 echo "$WARNING:This is a Bash function definition."