Sample Header Ad - 728x90

Can a shell script find all groups of consecutive lines matching the same regex and shuffle them?

0 votes
5 answers
200 views
I'm writing quizzes for my students in a markdown language. One of the quizzes might look like this: % QUESTION Who played drums for The Beatles? (X) Ringo ( ) John ( ) Paul ( ) George % QUESTION What is the first line of MOBY DICK? (X) Call me Ishmael. ( ) foo ( ) bar ( ) spam ( ) eggs I'd like to randomize all of these multiple choice options. So, I think I need a shell script that: 1) Finds all blocks of consecutive lines that start with (X) or ( ). 2) Shuffles each of these blocks of lines. Is this possible? I know that shuf and sort -R will randomize the lines of any text but I'm not sure of how to go about isolating these blocks of options.
Asked by Brian Fitzpatrick (2907 rep)
Jan 6, 2021, 08:24 AM
Last activity: Jan 7, 2021, 03:46 AM