Randomly select a line in every block of N lines
2
votes
2
answers
464
views
I'd like to randomly select a line after a given number of lines. For example here's my input:
8 blue
8 red
8 yellow
8 orange
3 pink
3 white
3 cyan
3 purple
1 magenta
1 black
1 green
1 brown
and with random selection a line from every four lines, my output would be:
8 orange
3 pink
1 green
The best I've come up with is:
awk '!(NR%4){a=NR+4};NR<=a|"shuf -n 1"'
but it doesn't work.
Asked by mtherk16
(21 rep)
Nov 17, 2017, 12:32 PM
Last activity: Nov 17, 2017, 03:37 PM
Last activity: Nov 17, 2017, 03:37 PM